Search code examples
iosaudiocallbackaudiosession

Detect (listen to) audio route change in iOS 7


Just starting development for iOS 7, and found that AudioSession related functions and PropertyListeners are deprecated in iOS 7.

Before I use the following method to detect if a headset has been plugged in or unplugged from the device:

    /* add callback for device route change */
    AudioSessionAddPropertyListener (
                                     kAudioSessionProperty_AudioRouteChange,
                                     audioRouteChangeListenerCallback,
                                     (__bridge void *)(self));

Then implement the listener callback to do different things to the internal algorithms. Now iOS 7 deprecated it and there's no documentations on any alternative, Is there any solutions by experts here? Thanks!


Solution

  • Handle the notification AVAudioSessionRouteChangeNotification (Available in iOS 6.0 and later.)