出回っている情報がわりと古くなっていて、アプリの起動時からイヤフォンがささっているとうまく認識されなかったりするので、最新の情報を共有しておきます。
- (BOOL)headphonesArePlugged
{
AVAudioSession * session = [AVAudioSession sharedInstance];
__block BOOL plugged = NO;
AVAudioSessionRouteDescription * routeDesc = session.currentRoute;
[routeDesc.outputs enumerateObjectsUsingBlock:^(AVAudioSessionPortDescription * desc, NSUInteger idx, BOOL *stop){
if ([desc.portType isEqualToString:AVAudioSessionPortHeadphones]) {
plugged = YES;
}
}];
return plugged;
}
これで端末にヘッドフォンがささっているかを取得できます。