ビデオを再生するためのAVPlayerを備えたアプリがあります。ユーザーがリモコンのボタンを押したことを検出できるようにしたいと考えています。次のメソッドを実装しようとしましたが、remoteControlReceivedWithEvent() はコントロール イベントに応答しません。
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl) {
if (event.subtype == UIEventSubtypeRemoteControlPlay) {
NSLog(@"play");
} else if (event.subtype == UIEventSubtypeRemoteControlPause) {
NSLog(@"pause");
} else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(@"toggle");
}
}
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
// Setup Apple TV control events
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
// Remove Apple TV control events
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
どんな助けでも大歓迎です、ありがとう!