iOS13適配MPRemoteCommandCenter奔潰問題

幾年前開源過一款音樂播放器,最近整理項目,發(fā)現其運行閃退,原來又是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.'

通過調試發(fā)現是以下方法適配造成的問題:
image.png

具體來說就是方法需要實現MPRemoteCommandHandlerStatus的函數回調

eg:

...
    // 直接使用sharedCommandCenter來獲取MPRemoteCommandCenter的shared實例
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    
    // 啟用播放命令 (鎖屏界面和上拉快捷功能菜單處的播放按鈕觸發(fā)的命令)
    commandCenter.playCommand.enabled = YES;
    // 為播放命令添加響應事件, 在點擊后觸發(fā)
    [commandCenter.playCommand addTarget:self action:@selector(playAction)];
...
//方法實現需要加上MPRemoteCommandHandlerStatus回調
-(MPRemoteCommandHandlerStatus)playAction
{
    [[MusicViewController sharedInstance].streamer play];
    return MPRemoteCommandHandlerStatusSuccess;
}

以上

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

?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容