【问题标题】:iPhone headset play button clickiPhone耳机播放按钮点击
【发布时间】:2012-03-21 01:45:42
【问题描述】:

我想检测 iPhone 上的耳机按钮点击,请参阅 Detect headset button click on 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];
}

我的问题是我无法捕获远程控制事件。单击耳机上的播放或暂停按钮时,控制台不打印任何内容!谁能帮我?谢谢。

【问题讨论】:

    标签: ios headset remote-control


    【解决方案1】:

    您的 Info.plist 是否已更新以表明您支持音频?

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

    添加新行,然后选择“必需的背景模式”。在出现在其下方/旁边的“项目 0”中,选择“应用播放音频”。

    【讨论】:

    • @SmeegolXie 您需要提供有关您尝试过和未尝试过的更多信息。
    • 这个应用不是播放音频,只是想捕捉耳机的按钮点击事件。我的同事告诉我,如果不播放音频,就无法检测到播放/暂停事件。对吗?我不能在不播放音频的情况下通过耳机捕捉播放/暂停事件吗?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    相关资源
    最近更新 更多