【问题标题】:How can i detect when play button is pressed in a bluetooth keyboard in iOS我如何检测iOS中的蓝牙键盘何时按下播放按钮
【发布时间】:2014-05-07 09:40:19
【问题描述】:

我想检测连接到 ipad 的蓝牙键盘何时按下播放/暂停音乐按钮。键盘是“ACTECK FT-850”。

我正在使用这种方法来检测其他按钮。

-(NSArray * ) keyCommands
{

if ([[[UIDevice currentDevice] systemVersion] intValue] !=7) return nil;

UIKeyCommand *Letter = [UIKeyCommand keyCommandWithInput: @"a" modifierFlags: 0 action: @selector(Letter:)];

UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputUpArrow modifierFlags: 0 action: @selector(upArrow:)];

    return [[NSArray alloc] initWithObjects: upArrow, Letter,nil];
}

- (void) Letter: (UIKeyCommand *) keyCommand
{
        NSLog(@"LETRA A");
}

- (void) upArrow: (UIKeyCommand *) keyCommand
{
        NSLog("Do something");
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

效果很好,但我不知道在KeyCommandWithInput 中输入了什么字母 o 命令来检测“播放/暂停”音乐按钮,...我也已经尝试过了:

-(void)viewDidAppear:(BOOL)animated
{
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent
{
    NSLog(@"ENTER TO REMOTE CONTROL");
    if (theEvent.type == UIEventTypeRemoteControl) {
        switch(theEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:

                NSLog(@"SE TOCO EL BOTON PLAY/PAUSE");

            case UIEventSubtypeRemoteControlPlay:

                NSLog(@"SE TOCO EL BOTON PLAY");

                break;
            default:
                return;
        }
    }
}

但是当我按下按钮时,永远不会调用remoteControlReceivedWithEvent

请帮帮我。

【问题讨论】:

    标签: ios bluetooth media-player bluetooth-lowenergy ios-bluetooth


    【解决方案1】:

    我认为这是相同的问题,但答案更多但解决方案有限!

    1-Detect Bluetooth answer/end-call button on iPhone

    2-Get the action of a connected bluetooth earphone in IOS7

    根据我的研究,有些人通过“remoteControlReceivedWithEvent”从他们的蓝牙设备收到了一些事件,但不是全部!像你我这样的人却一无所获!根据此评论,很少有人收到所有主题(来自上面链接中的一个 cmets “因为我的音乐应用程序可以通过上面的代码由蓝牙耳机完美控制,我认为它也应该适用。”!)

    我也试过Core Bluetooth,但它只支持LEB(低功耗蓝牙设备)! https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1

    此外,一些帖子表明可以使用经典蓝牙而不是“低能量”: How to use bluetooth classic instead of le 但它也有局限性(这篇文章是关于“MFi 配件”的!MFi 是为“iphone 制造”吗?!?!?!)

    来自上面的帖子: “非 LE 蓝牙设备需要经过 MFi 批准才能与外部附件框架一起使用(它需要使用特定的 Apple 芯片和专有通信协议)。您将无法构建应用程序来访问此设备“除非它使用更开放的蓝牙 LE,或者在其中包含用于标准蓝牙的芯片。可能有办法通过越狱来做到这一点,但我认识的几乎每个人都已经转向了蓝牙 LE。” !

    更多帖子:Connecting to a Bluetooth device from iOS, no MFi

    问候。

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多