iOS 音频播放iOS13上远程控制设置控制方法崩溃

使用MPRemoteCommandCenter 处理远程音频事件的播放的时候,
有些同学会用[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这个值.

意思就是这样了,根据这样的翻译可以很明确知道该怎么解决,要不换- (void)addTarget:(id)target action:(SEL)action;方法为- (id)addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler;要不就在- (void)addTarget:(id)target action:(SEL)action;的引用方法里添加返回值,例如:

- (MPRemoteCommandHandlerStatus)remotePauseEvent {
    
    return MPRemoteCommandHandlerStatusSuccess;
}

参考至这里

你可能感兴趣的:(iOS 音频播放iOS13上远程控制设置控制方法崩溃)