我已将以下代码用于 iPhone Control -
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
用于注册监听遥控器。完成后删除它 -
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
使应用程序canBecomeFirstResponder -
- (BOOL)canBecomeFirstResponder {
return YES;
}
使用委托方法来处理 iPhone 控制,例如双击主页按钮时播放和暂停
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl) {
if (event.subtype == UIEventSubtypeRemoteControlPlay) {
[audioPlayer play];
NSLog(@"play");
} else if (event.subtype == UIEventSubtypeRemoteControlPause) {
[audioPlayer stop];
NSLog(@"pause");
} else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(@"toggle");
}
}
}
就我而言,我能够处理播放和暂停。如果有任何问题,请告知。