我意识到这个问题之前已经被问过了,但我有和其他答案一样的代码(所以我认为)。图片和图像显示正常并更新,而新歌成为当前歌曲。我似乎无法获得播放/暂停和跳过按钮的工作。这是他使用的代码。iOS,MPNowPlayingInfoCenter暂停/播放按钮不起作用?
-(void)viewWillAppear:(bool)animated
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.type == UIEventTypeRemoteControl) {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:[self playPauseButtonPressed:nil];
NSLog(@"play pause button remote pressed");
break;
case UIEventSubtypeRemoteControlBeginSeekingForward:[self skipButtonPressed:nil];
NSLog(@"Skip remote pressed");
break;
default: break;
}
}
}
您发布的代码有效。只要您调用'beginReceivingRemoteControlEvents'并且您是第一响应者,您将收到远程控制事件。 – 2016-07-14 10:57:32