How to make the application work with the media control buttons on the lock screen?

In recent versions of iOS, applications have some access to the media control buttons on the lock screen, for example, the Play / Pause button:

enter image description here

It looks like buttons should work with the MPMusicPlayerController class, right? Is there a way to get raw events from buttons? Because the music player seems to offer an API to send MPMediaItem s bundle. What if my application is, for example, a radio that needs to control the buttons differently?

+7
source share
1 answer

After a bit more searching, I found this related question that makes everything clear. The music player controller class is actually not the right way, the trick is to subscribe to remote events in your controller:

 - (void) viewDidAppear: (BOOL) animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; } - (BOOL) canBecomeFirstResponder { return YES; } - (void) remoteControlReceivedWithEvent: (UIEvent*) event { // see [event subtype] for details } 
+8
source

All Articles