Easily respond to remote control events. It also allows you to control your application with a headset.
In this case, you can call the viewDidLoad call:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder];
And you must answer both
- (BOOL)canBecomeFirstResponder { return YES; }
and
- (void)remoteControlReceivedWithEvent:(UIEvent *)event { switch (event.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: if (audio.rate == 0.0) { [audio play]; } else { [audio pause]; } break; case UIEventSubtypeRemoteControlPlay: [audio play]; break; case UIEventSubtypeRemoteControlPause: [audio pause]; break; default: break; } }
Bjarne mogstad
source share