Lockscreen iPod Control for Native Application

How can I use iPod screen lock controls for my own application?

I tried MPNowPlayingInfoCenter, but if I set the information, it will not be displayed anywhere; Not on the lock screen, and not broadcast on AppleTV.

I use AVPlayer to play my audio files.

+4
source share
1 answer

Take a look at Media Remote Control .

Here's how to listen for remote control events in a subclass of UIViewController . First, include the controller in the responder chain, otherwise the events will be redirected to the application delegate:

 - (BOOL)canBecomeFirstResponder { return YES; } 

If necessary, tell the application to start receiving events and making your controller the first responder:

 // maybe not the best place but it works as an example - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; } 

Then answer them:

 - (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent { if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: [self playOrStop: nil]; break; case UIEventSubtypeRemoteControlPreviousTrack: [self previousTrack: nil]; break; case UIEventSubtypeRemoteControlNextTrack: [self nextTrack: nil]; break; default: break; } } } 
+12
source

Source: https://habr.com/ru/post/1388514/


All Articles