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:
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; } } }
source share