I have a Catalyst application that uses (as expected) MPNowPlayingInfoCenter to set the now playing info and MPRemoteCommandCenter to get the media events for play/pause/stop/favorite/etc.
The code is shared on iOS, tvOS and watchOS and it works correctly there. It seems not to work on macOS (app is compiled as a Catalyst application) on Big Sur (and Monterey, fwiw). Media keys on the keyboard starts the Music app, the music part of the control center do not show now playing info (nor the media controls there send messages to the app).
I seem to remember that it used to work in Catalina (at least the media key part) and for sure it used to work in a precedent version of the same app that used to be an UIKit one.
Is this a bug (worth a feedback to Apple) or something wrong on my side? I forgot some magic capability for macOS? App is sandboxed and uses hardened runtime, in case this is significant.
Thank you for any hint!
I've somewhat figured this out. I can get skip to work but I still haven't managed to get play/pause from the keyboard to work.
The thing that I was missing is on macOS you need to update the playing state on MPNowPlayingInfoCenter. It can't just infer it from the AVAudioSession like it does on other platforms.
.i.e.
MPNowPlayingInfoCenter.default().playbackState = .playing
Since I started doing that my app shows up in 'Now Playing' and all the controls work fine there. I just can't figure out why play/pause on the keyboard still doesn't work.