【发布时间】:2016-11-26 00:29:06
【问题描述】:
我正在尝试检测用户是否按下耳机键,因为我正在使用 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 类中使用了所有方法。
【问题讨论】:
-
在为 MPRemoteCommandCenter 定义选择器时是否缺少:在选择器中,因为方法需要一个参数?
-
@ldindu 我没有错过
-
我也想知道。从那以后你找到解决方案了吗?
-
以后没有客户跳过这个选项@GyörgyBenedek
标签: ios objective-c iphone remote-access headphones