gpt4 book ai didi

ios - 使用 native iOS 7 SDK 检测耳机插孔上的插入和拔出事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:23:50 26 4
gpt4 key购买 nike

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

最佳答案

试试这个:

[[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) {

}
}

关于ios - 使用 native iOS 7 SDK 检测耳机插孔上的插入和拔出事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23140464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com