How can I get the actions like button pushed of a connected bluetooth earphone in IOS7? I was thinking about using corebluetooth.framework,but it can only be used for BLE device while there is on BLE earphone as I know. So is there any other method I can use to do that?Or is there any other framework can be used to connect to a non-IOS device? Thanks
2 Answers
It's same way with headphone wire.
Once you should receive control events, add following code in proper position:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
And remove receive events, add following code in proper position:
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
RootViewController or the controller for just receive events should add:
- (BOOL)canBecomeFirstResponder {
return YES;
}
Following code is to do actions about clicking different buttons:
- (void)remoteControlReceivedWithEvent:(UIEvent *)event{
case UIEventSubtypeRemoteControlTogglePlayPause:
break;
case UIEventSubtypeRemoteControlPlay:
break;
case UIEventSubtypeRemoteControlPause:
break;
default:
break;
}
}
Here is define of UIEventSubtype
typedef NS_ENUM(NSInteger, UIEventSubtype) {
// available in iPhone OS 3.0
UIEventSubtypeNone = 0,
// for UIEventTypeMotion, available in iPhone OS 3.0
UIEventSubtypeMotionShake = 1,
// for UIEventTypeRemoteControl, available in iOS 4.0
UIEventSubtypeRemoteControlPlay = 100,
UIEventSubtypeRemoteControlPause = 101,
UIEventSubtypeRemoteControlStop = 102,
UIEventSubtypeRemoteControlTogglePlayPause = 103,
UIEventSubtypeRemoteControlNextTrack = 104,
UIEventSubtypeRemoteControlPreviousTrack = 105,
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
UIEventSubtypeRemoteControlEndSeekingBackward = 107,
UIEventSubtypeRemoteControlBeginSeekingForward = 108,
UIEventSubtypeRemoteControlEndSeekingForward = 109,
};
And here is the link for Remote Control Events. Hope to help you.

- 2,768
- 1
- 15
- 20
-
@user3309824 Does your problem fix? – simalone Feb 24 '14 at 11:13
-
One more question,can remote control be used in connected bluetooth earphone?I did some tests,it seems not work very good. – JadenGuo Feb 24 '14 at 11:19
-
Because my music app can be controlled perfectly by bluetooth earphone through code above, I think it should be applicable as well. – simalone Feb 24 '14 at 11:42
-
in my test,when I push the play button,it just play the song in iTunes rather than doing the method in switch. – JadenGuo Feb 24 '14 at 11:50
-
The program cannot jump to canBecomeFirstResponder.I do not know why. – JadenGuo Feb 24 '14 at 11:52
-
Where do you put `canBecomeFirstResponder `? MainViewConteroller? – simalone Feb 24 '14 at 11:54
-
If `[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];` but can't receive event by your app, that's the problem of `canBecomeFirstResponder ` where you put. Writing a test project to test code in document maybe help you understand. – simalone Feb 24 '14 at 12:05
-
Now it can jump to canBecomeFirstResponder.But still can not get the control event. – JadenGuo Feb 24 '14 at 13:06
As of my research, some person received some event from their bleu-tooth devices via "remoteControlReceivedWithEvent" but not all of them! Some are receiving none! And very few are receiving all of them!
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.