使用MPRemoteCommandCenter 處理遠(yuǎn)程音頻事件的播放的時(shí)候,
有些同學(xué)會(huì)用[pauseCommand addTarget:self action:@selector(remotePauseEvent)]這個(gè)方法來(lái)處理,但是在iOS13后蘋(píng)果官方在這個(gè)方法有要求了,官方文檔這么寫(xiě)的
// 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
翻譯一下其實(shí)意思就是 建議用
addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler;這個(gè)方法來(lái)為其添加本地事件處理,但是也可以用- (void)addTarget:(id)target action:(SEL)action;方法來(lái)處理,用- (void)addTarget:(id)target action:(SEL)action;方法處理時(shí)候需要返回MPRemoteCommandHandlerStatus這個(gè)值.
意思就是這樣了,根據(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;
}
參考至這里