iOS-判断耳机是否插入

录音过程有时候需要判断用户当前是插入耳机,具体判断如下:

- (BOOL)isHeadSetPlugging {
    AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
    for (AVAudioSessionPortDescription* desc in [route outputs]) {
        if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones])
            return YES;
    }
    return NO;
}

你可能感兴趣的:(iOS-判断耳机是否插入)