iOS13适配

iOS13适配MPRemoteCommandCenter奔溃问题

2020-03-02  本文已影响0人  流年划过颜夕

几年前开源过一款音乐播放器,最近整理项目,发现其运行闪退,原来又是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

上一篇下一篇

猜你喜欢

热点阅读