Skip to content

Instantly share code, notes, and snippets.

@brianpartridge
Last active August 29, 2015 13:56
Show Gist options
  • Save brianpartridge/8939270 to your computer and use it in GitHub Desktop.
Save brianpartridge/8939270 to your computer and use it in GitHub Desktop.
An example of how to add keyboard commands to Debug builds of an iOS app. From http://cocoa.tumblr.com/post/75111441462/supporting-keyboard-shortcuts-without-uitextview
#ifdef DEBUG
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (NSArray *)keyCommands {
static NSArray *keyCommands;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
keyCommands = @[[UIKeyCommand keyCommandWithInput:UIKeyInputEscape
modifierFlags:UIKeyModifierCommand
action:@selector(handleEscapeCommand:)]];
});
return keyCommands;
}
- (void)handleEscapeCommand:(UIKeyCommand *)keyCommand {
[[Session currentSession] disconnect];
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment