I have an iOS application that plays audio files from the server.

If you lock the screen during playback, a standard area with audio controls appears on the lock screen. The same area is in the bottom curtain (see screenshots). How does my application need to interact with it? I need to implement at least two actions: play and stop. What is the name of this area with audio controls on the lock screen? Where to look for information on working with her?

Screen lock screen

Screen bottom curtain

  • one
    MPRemoteCommandCenter - Max Mikheyenko

1 answer 1

MPRemoteCommandCenter singleton is used for this MPRemoteCommandCenter

For example, you can specify what your application should do when the user clicks play:

 MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter]; remoteCommandCenter.playCommand.enabled = YES; //playCommandTarget это переменная, в которой вы сохраняете handler, чтобы можно было его потом убрать self.playCommandTarget = [remoteCommandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *_Nonnull event) { [self.player play]; // или как у вас там делается play return MPRemoteCommandHandlerStatusSuccess; // тут надо проверить запустилось ли воспроизведение на самом деле и вернуть соответствующий код }]; 

Remove the handler when not needed.

 MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter]; [remoteCommandCenter.playCommand removeTarget:self.playCommandTarget];