beginReceivingRemoteControlEvents not triggering events for Apple Music

我与影子孤独终老i 提交于 2019-12-03 13:08:44

Instead of using -(void)remoteControlReceivedWithEvent:(UIEvent *)event to track for the controls, use MPRemoteCommandCenter adding targets to each one of the controls:

Note: It's important to enable the controls before assigning a target.

[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(remotePlay)];

[MPRemoteCommandCenter sharedCommandCenter].pauseCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(remoteStop)];

[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand addTarget:self action:@selector(loadPreviousSong)];

[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand addTarget:self action:@selector(loadNextSong)];

Selectors:

-(void) remotePlay {
    [APP_DELEGATE PlayPauseMusic:nil];
}
-(void) remoteStop {
    [APP_DELEGATE PlayPauseMusic:nil];
}
-(void) loadNextSong {
    [APP_DELEGATE next:nil];
}
-(void) loadPreviousSong {
    [APP_DELEGATE previous:nil];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!