我意識到這個問題之前已經被問過了,但我有和其他答案一樣的代碼(所以我認爲)。圖片和圖像顯示正常並更新,而新歌成爲當前歌曲。我似乎無法獲得播放/暫停和跳過按鈕的工作。這是他使用的代碼。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