Detect Headphones

#1

Does anybody have a latest and greatest way of detecting if an iOS device is connected to headphones/external speaker?

Am I right in thinking that old methods of doing this using kAudioSession are now depreciated by Apple?
Thanks.

#2
1 Like
#3

Thanks for this.

For anyone else running into the same problem here is my modified code to work with c++, just place in a .mm file. Altered it a bit so it returns true if anything other than the internal speaker is being used (for cases of bluetooth speakers etc).

bool Headphones::isHeadsetPluggedIn() {
AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
for (AVAudioSessionPortDescription* desc in [route outputs]) {
    if ([[desc portType] isEqualToString:AVAudioSessionPortBuiltInSpeaker])
        return NO;
}
return YES;}
2 Likes