iPhone でヘッドセット ボタンのクリックを検出したい場合は、「iPhone SDK でヘッドセット ボタンのクリックを検出する」を参照してください。http://developer.apple.com/library/IOS/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.htmlに従って、次のようにコードを記述しましたが、動作しません!!
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
if (receivedEvent.type == UIEventTypeRemoteControl) {
NSLog(@"Remote Control Event");
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"UIEventSubtypeRemoteControlTogglePlayPause");
break;
default:
break;
}
}
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
私の問題は、リモート コントロール イベントをキャッチできないことです。ヘッドセットの再生または一時停止ボタンをクリックすると、コンソールに何も出力されません! 誰が私を助けることができます?ありがとうございました。