我正在尝试检测用户是否按下耳机键,因为我正在使用 2 种方法。
-(void)headsetMicrophoneDetection
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[MPRemoteCommandCenter sharedCommandCenter].togglePlayPauseCommand addTarget:self action:@selector(onTooglePlayPause)];
NSLog(@"calling headset method");
}
-(void)onTooglePlayPause
{
NSLog(@"kishore");
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent
{
NSLog(@"callig method to :)");
if (theEvent.type == UIEventTypeRemoteControl) {
switch(theEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"Hello");
break;
case UIEventSubtypeRemoteControlPlay:
NSLog(@"Hello 2");
break;
case UIEventSubtypeRemoteControlPause:
NSLog(@"Hello 3");
break;
case UIEventSubtypeRemoteControlStop:
NSLog(@"Hello 4");
break;
default:
return;
}
}
}
但是在调用此方法后,我没有得到,我的代码有什么问题,我启用了后台服务以进行音频检查,并且我在 NSObject 类中使用了所有方法。