iOS 音頻播放iOS13上遠(yuǎn)程控制設(shè)置控制方法崩潰

使用MPRemoteCommandCenter 處理遠(yuǎn)程音頻事件的播放的時(shí)候,
有些同學(xué)會(huì)用[pauseCommand addTarget:self action:@selector(remotePauseEvent)]這個(gè)方法來(lái)處理,但是在iOS13后蘋(píng)果官方在這個(gè)方法有要求了,官方文檔這么寫(xiě)的

// 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

翻譯一下其實(shí)意思就是 建議用addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler; 這個(gè)方法來(lái)為其添加本地事件處理,但是也可以用- (void)addTarget:(id)target action:(SEL)action;方法來(lái)處理,用- (void)addTarget:(id)target action:(SEL)action; 方法處理時(shí)候需要返回MPRemoteCommandHandlerStatus這個(gè)值.

意思就是這樣了,根據(jù)這樣的翻譯可以很明確知道該怎么解決,要不換- (void)addTarget:(id)target action:(SEL)action;方法為- (id)addTargetWithHandler:(MPRemoteCommandHandlerStatus(^)(MPRemoteCommandEvent *event))handler;要不就在- (void)addTarget:(id)target action:(SEL)action;的引用方法里添加返回值,例如:

- (MPRemoteCommandHandlerStatus)remotePauseEvent {
    
    return MPRemoteCommandHandlerStatusSuccess;
}

參考至這里

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

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容