问题
I am creating an application for iOS that can be controlled using the MPRemoteCommandCenter. This works fine.
When changing the application AVAudioSession category from AVAudioSessionCategoryPlayback to AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers, it stops receiving remote control events. This is fine.
But when I change the category back to AVAudioSessionCategoryPlayback, I do not receive events from MPRemoteCommandCenter as expected.
How can I reclaim "Now Playing" status for my application?
回答1:
I did discover that when setting AVAudioSessionCategory the options are retained. So by calling setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers) first and then setCategory(AVAudioSessionCategoryPlayback) later, the .MixWithOthers option was always in effect.
I was unable to find a AVAudioSessionCategoryOptions.None option, but supplying an empty array did reset the category options.
.setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
来源:https://stackoverflow.com/questions/32284272/losing-now-playing-status-from-mpremotecommandcenter