1

我想要在連接到ipad的藍牙鍵盤上按下播放/暫停音樂按鈕時檢測到該按鈕。鍵盤是「ACTECK FT-850」。如何在iOS中的藍牙鍵盤上按下播放按鈕時進行檢測

我使用這種方法來檢測其他按鈕。

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

它完美,但我不知道放什麼字母O命令KeyCommandWithInput用於檢測「播放/暫停」音樂鍵,......我已經嘗試過這樣:

-(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當我按下按鈕時從未被調用。

請幫幫我。

回答

0

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

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

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

由於我的研究,一些人通過「remoteControlReceivedWithEvent」,但不是所有的人得到了一些事件,從他們的吉爾齒設備!有些人喜歡你我都沒有收到任何東西!很少有人會根據此評論收到所有主題(來自上面鏈接的評論之一「因爲我的音樂應用程序可以通過藍牙耳機通過上面的代碼完美控制,我認爲它也應該適用。」)

我也試過核心藍牙,但它只支持LEB(低能量藍牙設備)! https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1

此外,一些帖子表明,它可以使用經典bleutooth而不是「低能量」! How to use bluetooth classic instead of le 但它也有侷限性,以及(後走約「MFI配件」 MFI是它的「 「)

來自上面的帖子: 」非LE藍牙設備需要MFi認證才能與外部附件框架一起使用(它需要使用特定的Apple芯片和專有通信協議),除非使用更開放的藍牙LE,或者將此芯片用於標準藍牙,否則您將無法構建應用程序來訪問此設備。可以通過越獄來做到這一點,但幾乎每個我認識的人都轉移到了藍牙LE。「 !

多崗:Connecting to a Bluetooth device from iOS, no MFi

問候。