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?
Asked
Active
Viewed 1,603 times
2
-
possible duplicate of [Is there an event for when the headphones are unplugged?](http://stackoverflow.com/questions/4452441/is-there-an-event-for-when-the-headphones-are-unplugged) – 0xced Apr 17 '14 at 18:20
-
Tutorial : http://www.makebetterthings.com/iphone/headphone-plug-in-plug-out-event-in-ios/ – Midhun MP Apr 17 '14 at 18:20
-
@0xced - The links provided in that page are broken. :( – yarlg Apr 17 '14 at 18:27
-
I just fixed the link. – 0xced Apr 17 '14 at 21:41
1 Answers
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