经过大量谷歌搜索,我找到了检测音频杰克的最佳和简单的解决方案
首先在代码中添加以下方法
- (BOOL)areHeadphonesPluggedIn {
NSArray *availableOutputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
for (AVAudioSessionPortDescription *portDescription in availableOutputs) {
NSLog(@"%@",portDescription.portType);
if ([portDescription.portType isEqualToString:AVAudioSessionPortHeadphones]) {
return YES;
}
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
然后测试它
if ([self areHeadphonesPluggedIn] == TRUE) {
NSLog(@"Device Detetcted. Headphone PluggedIn");
}
else {
NSLog(@"Device Not Detetcted. Headphone PluggedOut");
}
Run Code Online (Sandbox Code Playgroud)
非常简单!
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |