我想要在連接到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
當我按下按鈕時從未被調用。
請幫幫我。