我正在尝试为我的应用程序使用锁定屏幕/现在播放控件,但没有收到任何事件。文档使它看起来非常简单,所以当我没有得到任何结果时我有点惊讶。我的应用需要接收远程控制事件,以便在设备上播放音频之外的其他用途。我试图通过使用 NSLog 打印出一些确认来对此进行测试。我是否需要使用文档中未提及的音频或媒体框架?我没有收到任何警告或错误,所以我认为这不应该有任何问题...任何有关远程控制事件未注册原因的见解将不胜感激
以下是相关代码:
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//Register for lock screen controls
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//Unregister lock screen controls
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL)canBecomeFirstResponder{
return YES;
}
//Lock screen controls
- (void)remoteControlReceivedWithEvent:(UIEvent *)event{
NSLog(@"RECEIVED");
if (event.type == UIEventTypeRemoteControl) {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"RECEIVED");
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"RECEIVED");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"RECEIVED");
break;
default:
break;
}
}
}