首页 > 解决方案 > How to Hide MPCommandCenter manually?

问题描述

I am currently working on one Podcast app, in which we are using MPCommandCenter to enhance user experience to initialise MPCommandCenter I am using following code

let remoteCommands = MPRemoteCommandCenter.shared()

remoteCommands.playCommand.addTarget { event in
    // Perform play action
    return .success
}

remoteCommands.pauseCommand.addTarget { event in
    // Perform pause action
    return .success
}

After using this code MPCommandCenter properly display remote controls. But we have functionality that allow users to Close currently playing podcast. And I am not able to figure out the way to unregister commandcenter manually. Can anyone help me to figure this one out.

标签: iosswift

解决方案


remoteCommands.playCommand.removeTarget(self)
remoteCommands.pauseCommand.removeTarget(self)
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil

try? AVAudioSession.sharedInstance().setActive(false)

推荐阅读