幾年前開源過一款音樂播放器,最近整理項目,發(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;
}
以上