iosswiftavplayermpremotecommandcenter

How to remove MPRemoteCommandCenter from Notification Center


How to remove MPRemoteCommandCenter.shared() from Notification Center. I tried this code, but only commands and actions are disabling. I need complete notification to be removed from the Notification Center. When we kill app it doesn't appear in notification bar, I want the same thing to be done when I move to other screen.

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:)))
}

Solution

  • It disappears from Notification Center, if we use endReceivingRemoteControlEvents()