我想检测何时在连接到 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;
}
它工作得很好,但我不知道输入什么字母 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
当我按下按钮时永远不会被调用。
请帮我。