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 = [:]
}