While playing audio in background mode player controls appears on the lockscreen. How to remove it when the audio has stopped? If try to set:
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
player is still on the lockscreen, but the fields artist/song are empty
UPD (my code for audiosession):
in AppDelegate:
func setupAudioSession() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
try audioSession.setActive(true)
} catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
}
in Player class:
private func clearRemotePlayerInfo() { // call after stop button pressed
try? AVAudioSession.sharedInstance().setActive(false)
MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
}

TL;DR
Example on Github: https://github.com/JakubMazur/SO52243428
You shouldn't assign
nilto thisnowPlayingInfo.What you should do to achieve this is:
nowPlayingInfoSo the code will look like:
And it will behave like this:
EDIT:
I've wrote as simple as possible example for try it out. It's available on Github https://github.com/JakubMazur/SO52243428. Feel free to check it out and it it matches your case.