How do I know if an external headset is connected to the iPhone?

Is it possible to detect that the user has an external headset connected to the iPhoneโ€™s 3.5 mm jack or 30-pin jack? I want to output sound only to an external audio device and be silent if nothing is connected.

+3
objective-c iphone core-audio
source share
2 answers

The answer is very similar to the answer to this question , but you will want to get kAudioSessionProperty_AudioRoute .

+2
source share

Call this method to find out if a Bluetooth headset is connected.

First import this #import <AVFoundation/AVFoundation.h>

 - (BOOL) isBluetoothHeadsetConnected { AVAudioSession *session = [AVAudioSession sharedInstance]; AVAudioSessionRouteDescription *routeDescription = [session currentRoute]; NSLog(@"Current Routes : %@", routeDescription); if (routeDescription) { NSArray *outputs = [routeDescription outputs]; if (outputs && [outputs count] > 0) { AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0]; NSString *portType = [portDescription portType]; NSLog(@"dataSourceName : %@", portType); if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"]) { return YES; } } } return NO; } 
+1
source share

All Articles