ios - iPhone耳机播放按钮点击

标签 ios headset remote-control

我想检测 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];
}

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

最佳答案

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

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

Add the new line, and select "Required Background Modes". In the "Item 0" that appears under/next to it, select "App plays audio".

关于ios - iPhone耳机播放按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9797562/

相关文章:

Android:关于 MediaSessionManager 和 RemoteController 我不清楚的地方

ios - 快速使用耳机

ios - Firebase 存储为 url 返回 nil

ios - 如何在 Swift for Realm 模型中设置主键

ios - Swift:Watchkit 表未填充

Android MediaSession 回调。在耳机上将双击解释为 SKIP_TO_NEXT

android - 将耳机麦克风更改为内置麦克风

macos - 在Mac OS X上使用AudioUnit检测扬声器/耳机

mongodb - 如何禁用与 MongoDB 的远程连接?

ios - 从 Spritekit 纹理图集中加载纹理的最高效方法