1

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];
}

私の問題は、リモート コントロール イベントをキャッチできないことです。ヘッドセットの再生または一時停止ボタンをクリックすると、コンソールに何も出力されません! 誰が私を助けることができます?ありがとうございました。

4

1 に答える 1

1

Info.plist が更新され、オーディオをサポートしていることを示していますか?

http://www.iphonedevsdk.com/forum/iphone-sdk-development/44433-there-way-respond-clicks-headphone-buttons.htmlから

新しい行を追加し、「Required Background Modes」を選択します。その下/横に表示される「アイテム 0」で、「アプリがオーディオを再生」を選択します。

于 2012-03-21T01:59:51.087 に答える