简体   繁体   English

如何在iOS的蓝牙键盘中检测何时按下播放按钮

[英]How can i detect when play button is pressed in a bluetooth keyboard in iOS

I want to detect when play/pause music button is pressed in a bluetooth keyboard connected to the ipad. 我想检测连接到ipad的蓝牙键盘中何时按下了播放/暂停音乐按钮。 The keyboard is " ACTECK FT-850 ". 键盘为“ ACTECK FT-850 ”。

I'm using this method to detect other buttons. 我正在使用这种方法来检测其他按钮。

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

It works perfectly, but I dont know what letter o command put in KeyCommandWithInput for detect "Play/pause" music button,... I already try this too: 它工作正常,但是我不知道在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;
        }
    }
}

But remoteControlReceivedWithEvent never is called when I press the button. 但是当我按下按钮时,永远不会调用remoteControlReceivedWithEvent

Please help me. 请帮我。

I Think this si the same questions with more answer but limited solutions! 我认为这是相同的问题,答案更多,但解决方案有限!

1- Detect Bluetooth answer/end-call button on iPhone 1- 检测iPhone上的蓝牙接听/挂断按钮

2- Get the action of a connected bluetooth earphone in IOS7 2- 在IOS7中获得连接的蓝牙耳机的作用

As of my research, some person received some event from their bleu-tooth devices via "remoteControlReceivedWithEvent" but not all of them! 在我的研究中,有人通过“ remoteControlReceivedWithEvent”从其蓝牙设备收到了一些事件,但并非全部! Some like you and me are receiving none! 像您和我这样的人什么也没收到! And very few are receiving all of theme as per this comment (from one of the comments from the link above "because my music app can be controlled perfectly by bluetooth earphone through code above, I think it should be applicable as well." !) 而且很少有人收到此评论的主题信息(来自上面链接的评论之一:“因为通过上述代码,蓝牙耳机可以完美控制我的音乐应用,因此我认为它也应适用。”!)

I also tried Core Bluetooth but it only supports LEB (Low Energy Bluetooth devices)! 我也尝试了Core Bluetooth,但它仅支持LEB(低能耗蓝牙设备)! https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1 https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1

Also, some posts suggest it is possible to use Classic bleutooth instead of "Low Energy": How to use bluetooth classic instead of le But it has limitation as well (the post is taking about "MFi accessory"! MFi is it for "made for iphone" ?!?!?!) 另外,有些帖子建议可以使用经典蓝牙代替“低能耗”: 如何使用蓝牙经典代替le但它也有局限性(该帖子采用了“ MFi附件”! for iPhone”?!?!?!!)

from the post above: "A non-LE Bluetooth device needs to be MFi-approved to be used with the External Accessory framework (it needs to use a specific Apple chip and a proprietary communication protocol). You won't be able to build applications to access this device unless it either uses the more open Bluetooth LE or has this chip in it for standard Bluetooth. There might be ways to do this via jailbreak, but pretty much everyone I know has moved over to Bluetooth LE." 从上面的帖子中:“非LE蓝牙设备需要经过MFi批准才能与外部附件框架一起使用(它需要使用特定的Apple芯片和专有的通信协议)。您将无法构建应用程序访问此设备,除非它使用更开放的Bluetooth LE或其中包含用于标准Bluetooth的芯片。也许有一些方法可以通过越狱来做到这一点,但我认识的几乎每个人都已转移到Bluetooth LE。 !

more post: Connecting to a Bluetooth device from iOS, no MFi 更多文章: 从iOS连接到蓝牙设备,没有MFi

Regards. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM