首页 > 移动平台 > 详细

iOS检测耳机插入拔出

时间:2015-11-19 16:36:58      阅读:174      评论:0      收藏:0      [点我收藏+]

首先,需要导入两个框架技术分享

然后,注册通知检测耳机的插入与拔出操作

1     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(outputDeviceChanged:)name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
2     [[NSNotificationCenter defaultCenter]postNotificationName:AVAudioSessionRouteChangeNotification object:self];

通知方法

- (void)outputDeviceChanged:(NSNotification *)aNotification {
    AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
    for (AVAudioSessionPortDescription* desc in [route outputs]) {
        
    if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones])
            NSLog(@"有耳机");
    else{
        NSLog(@"没有耳机");
    }
        
    }
    
            
}

 

iOS检测耳机插入拔出

原文:http://www.cnblogs.com/luerniu/p/4977893.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!