簡體   English   中英

如何在iOS的藍牙鍵盤中檢測何時按下播放按鈕

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

我想檢測連接到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

請幫我。

我認為這是相同的問題,答案更多,但解決方案有限!

1- 檢測iPhone上的藍牙接聽/掛斷按鈕

2- 在IOS7中獲得連接的藍牙耳機的作用

在我的研究中,有人通過“ remoteControlReceivedWithEvent”從其藍牙設備收到了一些事件,但並非全部! 像您和我這樣的人什么也沒收到! 而且很少有人收到此評論的主題信息(來自上面鏈接的評論之一:“因為通過上述代碼,藍牙耳機可以完美控制我的音樂應用,因此我認為它也應適用。”!)

我也嘗試了Core Bluetooth,但它僅支持LEB(低能耗藍牙設備)! https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1

另外,有些帖子建議可以使用經典藍牙代替“低能耗”: 如何使用藍牙經典代替le但它也有局限性(該帖子采用了“ MFi附件”! for iPhone”?!?!?!!)

從上面的帖子中:“非LE藍牙設備需要經過MFi批准才能與外部附件框架一起使用(它需要使用特定的Apple芯片和專有的通信協議)。您將無法構建應用程序訪問此設備,除非它使用更開放的Bluetooth LE或其中包含用於標准Bluetooth的芯片。也許有一些方法可以通過越獄來做到這一點,但我認識的幾乎每個人都已轉移到Bluetooth LE。

更多文章: 從iOS連接到藍牙設備,沒有MFi

問候。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM