如何从通知中心删除 MPRemoteCommandCenter



如何从通知中心删除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:)))
}

如果我们使用endReceivingRemoteControlEvents(),它会从通知中心消失

最新更新