使用MPRemoteCommandCenter 處理遠程音頻事件的播放的時候,
有些同學(xué)會用[pauseCommand addTarget:self action:@selector(remotePauseEvent)]這個方法來處理,但是在iOS13后蘋果官方在這個方法有要求了,官方文檔這么寫的
// Target-action style for adding handlers to commands.
// Actions receive an MPRemoteCommandEvent as the first parameter.
// Targets are not retained by addTarget:action:, and should be removed from the
// command when the target is deallocated.
//
// Your selector should return a MPRemoteCommandHandlerStatus value when
// possible. This allows the system to respond appropriately to commands that
// may not have been able to be executed in accordance with the application's
// current state
翻譯一下其實意思就是 建議用
addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler;這個方法來為其添加本地事件處理,但是也可以用- (void)addTarget:(id)target action:(SEL)action;方法來處理,用- (void)addTarget:(id)target action:(SEL)action;方法處理時候需要返回MPRemoteCommandHandlerStatus這個值.
意思就是這樣了,根據(jù)這樣的翻譯可以很明確知道該怎么解決,要不換- (void)addTarget:(id)target action:(SEL)action;方法為- (id)addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler;要不就在- (void)addTarget:(id)target action:(SEL)action;的引用方法里添加返回值,例如:
- (MPRemoteCommandHandlerStatus)remotePauseEvent {
return MPRemoteCommandHandlerStatusSuccess;
}
參考至這里