我想检测何时播放/暂停音乐按钮被按下蓝牙键盘连接到ipad。键盘是"ACTECK 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就不会被调用。
请帮帮我。
发布于 2014-11-07 20:51:00
我认为这是同样的问题,更多的答案,但有限的解决办法!
1- Detect Bluetooth answer/end-call button on iPhone
2- Get the action of a connected bluetooth earphone in IOS7
在我的研究中,有些人通过"remoteControlReceivedWithEvent“从他们的bleu牙齿装置中收到了一些事件,但不是所有的!像你我这样的人一点也没收到!而且很少有人会收到这条评论的全部主题(来自上述链接的评论之一),“因为我的音乐应用程序可以通过上面的代码被蓝牙耳机完美地控制,我认为它也应该适用!”
我也尝试过核心蓝牙,但它只支持LEB (低能蓝牙设备)!ref/doc/uid/TP40013257-CH2-SW1
此外,一些帖子建议可以使用经典的漂白牙代替“低能量”:How to use bluetooth classic instead of le,但它也有局限性(帖子是关于"MFi配件“!)MFi是“为iphone制造”吗?!?!!)
从上面的帖子中可以看到:“一种非LE蓝牙设备需要经过MFi的批准,才能与外部附件框架一起使用(它需要使用特定的苹果芯片和专有通信协议)。除非它使用更开放的蓝牙LE或将该芯片作为标准蓝牙,否则您将无法构建访问该设备的应用程序。也许有办法通过越狱来实现这一点,但我知道的几乎每个人都已经转向了蓝牙。”
更多帖子:Connecting to a Bluetooth device from iOS, no MFi
致以问候。
https://stackoverflow.com/questions/22704159
复制相似问题