我正在尝试找到一种方法来检测Native iOS SDK中耳机插孔上的插入/拔出事件,特别是在最新版本(iOS 7)上。是否有办法在此版本中执行此操作?
答案 0 :(得分: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) {
}
}