1

I want to detect when play/pause music button is pressed in a bluetooth keyboard connected to the ipad. The keyboard is "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:

-(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.

Please help me.

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81

1 Answers1

0

I Think this si the same questions with more answer but limited solutions!

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

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

As of my research, some person received some event from their bleu-tooth devices via "remoteControlReceivedWithEvent" but not all of them! 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)! 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" ?!?!?!)

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." !

more post: Connecting to a Bluetooth device from iOS, no MFi

Regards.

Community
  • 1
  • 1
momo
  • 54
  • 7