【发布时间】:2015-01-31 01:38:24
【问题描述】:
我正在尝试检测headphones 何时插入 iPhone。我这样做是购买以下方法。
//Init the AVAudioSession
-(void)viewDidLoad
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
}
//Get the current audio session route
-(void)viewWillAppear
{
AVAudioSessionRouteDescription *route = [[AVAudioSession sharedInstance] currentRoute];
}
这很好用,route.inputs 和 route.outputs 将包含有线 iPhone 的 headphones 和 microphone headset,并在拔下耳机时显示内置接收器和内置麦克风。我遇到的问题是当我按下我的应用程序上的主页按钮时,它会移动到后台。当我将应用程序带回前台时, route.inputs 始终为空。我的问题是:当调用applicaionWillResign active 时,我是否需要在我的appDelegate 中设置[[AVAudioSession sharedInstance] setActive:NO error: &activiationError]?因为当 route.inputs 返回空时,耳机仍然插入并且应该被检测到。任何帮助,将不胜感激。谢谢。
【问题讨论】:
标签: ios objective-c iphone