【问题标题】:Detect plugged & unplugged event on headphone jack with native iOS 7 SDK使用原生 iOS 7 SDK 检测耳机插孔上的插入和拔出事件
【发布时间】:2014-06-02 03:46:14
【问题描述】:

我正在尝试找到一种方法来检测 Native iOS SDK 中耳机插孔上的插入/拔出事件,特别是在最新版本 (iOS 7) 上。有没有办法在这个版本中做到这一点?

【问题讨论】:

标签: ios


【解决方案1】:

试试这个:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChanged:) name:AVAudioSessionRouteChangeNotification object:nil];


- (void)routeChanged:(NSNotification *)notification {
    NSNumber *reason = [notification.userInfo objectForKey:AVAudioSessionRouteChangeReasonKey];

    if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {

    } else if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {

    }
}

【讨论】:

    猜你喜欢
    • 2013-11-11
    • 2017-04-24
    • 2016-04-14
    • 2011-04-17
    • 2013-05-08
    • 2013-07-17
    • 2016-06-10
    • 2013-05-01
    • 2013-05-27
    相关资源
    最近更新 更多