我有一个播放音乐并想使用锁屏控制(播放/暂停)的应用程序。使用 NSLog,我可以看到我的应用程序是按钮触发器,但不是 UIEventSubtypeRemoteControlTogglePlayPause。
这是我的一些代码:
- (void)viewDidLoad {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
NSLog(@"REMOTE RECEIVE");
if (receivedEvent.type == UIEventTypeRemoteControl)
{
NSLog(@"received remote event");
switch (receivedEvent.subtype)
{
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"toggle button received");
//[self togglePlayPauseTapped: nil];
break;
default:
break;
}
}
我从 NSLog 输出中得到“REMOTE RECEIVE”和“received remote event”,但没有在 ...TogglePlayPause 中的行。
有任何想法吗?