External integration with Bluetooth keyboard in IOS 7

I need to support external keyboard functionality in my application, and you need to use keyboard shortcuts like Alt + Tab tab to trigger any event. In iOS 6, I redefined

- (void)sendEvent:(UIEvent *)anEvent; 

in a subclass of UIApplication to get the keystroke combinations on the external keyboard.

But now I am testing my application in IOS 7, and sendEvent does not even seem to be called for any hardware key press.

Any solutions ..?

+7
ios7 bluetooth keyboard uiapplication
source share
1 answer

There is a 100% supported way to handle keyboard shortcuts on a Bluetooth keyboard in iOS 7 using the new UIKeyCommand class and UIResponder chain. I made a blog about it , but here's the gist:

Somewhere in the responder chain, add the keyCommands method, which returns an array of UIKeyCommand objects:

 - (NSArray *)keyCommands { UIKeyCommand *commandF = [UIKeyCommand keyCommandWithInput:@"f" modifierFlags:UIKeyModifierCommand action:@selector(handleCommandF:)]; return @[commandF]; } 

Then, when ⌘F is pressed (as text input), the responder chain will look for this handleCommandF method. If there are several definitions, then it will use the narrowest area (for example, the view itself takes precedence over the ViewController).

Note that this will only work if the input (e.g. UITextField or UITextView ) is the first responder. If you want to use β€œglobal” shortcuts in your application, you can do a trick in which you hide the UITextField off-screen and focus on that.

+18
source share

All Articles