Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement the new iPad Pro Keyboard Shortcuts feature?

Apple's iPad Pro page talks about a new keyboard shortcut feature:

Shortcuts at your fingertips.

iOS 9 works seamlessly with the Smart Keyboard, adding a variety of useful QuickType features to your iPad Pro.

enter image description here

Time-saving Shortcuts

Use keyboard shortcuts to perform even more commands on your iPad Pro — like switching between apps or bringing up search with your Smart Keyboard. And interact with your apps using their own built-in custom shortcuts. Just press and hold a key like Command, Option, or Control to see shortcuts in any app.

I tried searching the iOS 9 and iOS 9.1 API pages and can't find anything about keyboard shortcuts.

How can I implement this feature in my app, or where can I find the documentation that talks about it?

like image 514
Senseful Avatar asked Nov 06 '15 20:11

Senseful


1 Answers

It looks like most of this feature had already existed as of iOS 7, called UIKeyCommand.

The only thing that was added is the discoverabilityTitle, which is used to display the available command names on any iPad running iOS 9+. You can see this menu in the simulator by holding down the command key on any screen that provides keyboard shortcuts (e.g. the iOS home screen).

enter image description here

There's a nice write up on NSHipster about this, which includes these iOS 9 features.

Essentially you need to do the following:

  1. Allow the view controller to become first responder.
  2. Return an array of UIKeyCommands in the view controller's keyCommands method.
  3. Handle the action that is sent to the view controller.
like image 185
Senseful Avatar answered Oct 29 '22 21:10

Senseful