2

I'm trying to find a way to detect the plugged/unplugged event on headphone Jack in Native iOS SDK, specifically on latest version (iOS 7).Is there a way to do it in this version?

yarlg
  • 3,481
  • 3
  • 20
  • 20

1 Answers1

1

Try this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChanged:) name:AVAudioSessionRouteChangeNotification object:nil];


- (void)routeChanged:(NSNotification *)notification {
    NSNumber *reason = [notification.userInfo objectForKey:AVAudioSessionRouteChangeReasonKey];

    if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {

    } else if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {

    }
}
Vsejed
  • 11
  • 2