iOS检测耳机是否插入

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    #import <AVFoundation/AVFoundation.h>  
      
    - (BOOL)isHeadsetPluggedIn {  
        AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];  
        for (AVAudioSessionPortDescription* desc in [route outputs]) {  
            if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones])  
                return YES;  
        }  
        return NO;  
    }