iOS13适配MPRemoteCommandCenter奔溃问题

几年前开源过一款音乐播放器,最近整理项目,发现其运行闪退,原来又是iOS13弄出的幺蛾子,没办法只有分析奔溃原因了。

//奔溃Log:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported action method signature. Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.'

通过调试发现是以下方法适配造成的问题:
image.png

具体来说就是方法需要实现MPRemoteCommandHandlerStatus的函数回调

eg:

...
    // 直接使用sharedCommandCenter来获取MPRemoteCommandCenter的shared实例
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    
    // 启用播放命令 (锁屏界面和上拉快捷功能菜单处的播放按钮触发的命令)
    commandCenter.playCommand.enabled = YES;
    // 为播放命令添加响应事件, 在点击后触发
    [commandCenter.playCommand addTarget:self action:@selector(playAction)];
...
//方法实现需要加上MPRemoteCommandHandlerStatus回调
-(MPRemoteCommandHandlerStatus)playAction
{
    [[MusicViewController sharedInstance].streamer play];
    return MPRemoteCommandHandlerStatusSuccess;
}

以上

源码地址:
https://github.com/liunianhuaguoyanxi/ZWTMusicPlayer

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容