如何从通知中心删除 MPRemoteCommandCenter

问题描述 投票:0回答:2

如何从通知中心删除

MPRemoteCommandCenter.shared()
。我尝试了这段代码,但只有命令和操作被禁用。我需要从通知中心删除完整的通知。当我们杀死应用程序时,它不会出现在通知栏中,我希望当我移动到其他屏幕时也能完成同样的事情。

func removeCommanCenter() {

let commadCenter = MPRemoteCommandCenter.shared()

    commandCenter.previousTrackCommand.isEnabled = false
    commandCenter.nextTrackCommand.isEnabled = false
    commandCenter.playCommand.isEnabled = false
    commandCenter.pauseCommand.isEnabled = false
    commandCenter.changePlaybackPositionCommand.isEnabled = false

    commandCenter.nextTrackCommand.removeTarget(self, action: #selector(self.loadNextVideos))
    commandCenter.previousTrackCommand.removeTarget(self, action: #selector(self.loadPrevoiusVideos))
    commandCenter.playCommand.removeTarget(self, action: #selector(self.audioPlayerView.customPlayer?.togglePlay(_:)))
    commandCenter.pauseCommand.removeTarget(self, action: #selector(self.audioPlayerView.customPlayer?.togglePlay(_:)))
    commandCenter.changePlaybackPositionCommand.removeTarget(self, action: #selector(self.audioPlayerView.customPlayer?.handleChangePlaybackPositionCommandEvent(event:)))
}
ios swift avplayer mpremotecommandcenter
2个回答
1
投票

如果我们使用

endReceivingRemoteControlEvents()

,它就会从通知中心消失

0
投票

别忘了将player设置为nil

self.player = nil
MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
UIApplication.shared.endReceivingRemoteControlEvents()
© www.soinside.com 2019 - 2024. All rights reserved.