0
我想檢測用戶是否按下了耳機鍵,因爲我使用了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;
}
}
}
但調用此方法餘did't得到的,什麼是錯在我的代碼和我啓用後臺服務,爲音頻檢查&我使用這NSObject類的所有方法之後。
您是否缺少:在您的選擇器中爲MPRemoteCommandCenter定義選擇器時,因爲該方法需要參數? – ldindu
@ldindu不,我沒有錯過 –