4

I'd love to find out when a Bluetooth device (earpiece, microphone, car audio connection, etc.) becomes available so I can change the audio options in my app's UI.

As of iOS 6, there are notifications which are supposed to fire when interruptions and route changes happen. The notification that looks potentially the most useful is the AVAudioSessionRouteChangeNotification one, where the notification's userInfo dictionary will come with a AVAudioSessionRouteChangeReasonKey which gives useful info like AVAudioSessionRouteChangeReasonNewDeviceAvailable and AVAudioSessionRouteChangeReasonOldDeviceUnavailable.

Unfortunately, if my audio session starts off without using Bluetooth (e.g. using the built-in microphone or a wired headset instead), I never hear about any Bluetooth audio device becoming available or unavailable via these route change notifications, irregardless of which device I turn on and off and make available.

Another option (which I haven't tried yet) is AVAudioSessionDelegate, which had a protocol method named inputIsAvailableChanged:. I use the word had because the protocol is fully deprecated as of iOS 6 hence the introduction of the above notifications.

Would anyone know how to do this right (where I get reliable notifications of a Bluetooth device becoming available or unavailable), or if there are other options I can consider?

allprog
  • 16,540
  • 9
  • 56
  • 97
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Have you seen [Technical Q&A QA1799](https://developer.apple.com/library/ios/qa/qa1799/_index.html)? The last paragraph seems to be what you are looking for. I guess you can't monitor the availabilty changes but when the user wants to change, you can use the [availableInputs](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html#//apple_ref/occ/instp/AVAudioSession/availableInputs) property to offer a list. – allprog Mar 04 '14 at 19:02
  • Thanks for looking at my question @allprog. I am indeed using the "`availableInputs`" property to get that list of available inputs (which came from the answer to [this related question that I asked a couple months back](http://stackoverflow.com/questions/20896528/how-to-find-bluetooth-audio-devices-in-ios)), but now I'm trying to find out if there's a way my app can be notified when a Bluetooth audio device becomes available to the app to use. – Michael Dautermann Mar 04 '14 at 19:14
  • Yeah, I get that, but the notifications seem to be generated only if there is a change in the route. A new option becoming available does not fall into this category in my opinion. The framework seems to handle the app as a client who tells what it prefers and if the system is able to fulfill it, then it will, but otherwise the app is not notified about other options. You may monitor them "manually" by periodically checking the availableInputs. Though, I think you will be better off following the standard way of operation. – allprog Mar 04 '14 at 19:24
  • is there a "standard way of operation" that allows an app to become aware when a Bluetooth device is turned on, aside from polling "`availableInputs`" (which is really awful)? – Michael Dautermann Mar 04 '14 at 19:25
  • Unfortunately, bluetooth audio devices are handled completely by the system. There is no way to scan for those. Polling actually may not be that bad but as soon as your app has to do it in the background, serious hacking has to be applied. – allprog Mar 04 '14 at 19:35

0 Answers0