Technical Q&A QA1924

Opening Keyboard Settings from a Keyboard Extension

Q:  I want to make it easier for the users of my iOS custom keyboard to enable it. How can I open Keyboard Settings from my keyboard extension?

A: iOS custom keyboard extensions can replace the iOS system keyboard with a custom keyboard for use in all apps. To enable a custom keyboard, an iOS user must open the Settings app and navigate to General > Keyboard > Keyboards > Add A New Keyboard.

You can make it easier for your customers to enable your custom keyboard by opening Keyboard settings directly. To do this, you will need to add a URL Type with a URL Scheme of "prefs" to your Xcode project, then call openURL with the URL scheme shown in Listing 1 from an appropriate UI in your extension or containing app.

Listing 1  URL scheme to open Settings app to Keyboards.

prefs:root=General&path=Keyboard

Add a URL Scheme to your project

You need to add a URL Type with a URL Scheme of "prefs" to your Xcode project. Without it, iOS will not recognize this URL scheme and the Settings app will not open.

To add a URL Type, open your Xcode project then follow these steps (illustrated in Figure 1):

  1. Navigate to your project's Target.

  2. Select the Info tab.

  3. Open the URL Types disclosure triangle and click the plus (+) button to add a new type.

  4. Type in "prefs" in the URL Scheme field. Leave the remaining items at their defaults.

Figure 1  Adding a URL Type with a URL Scheme of 'prefs'.

Open the URL Scheme

To use this URL scheme in your app, open it as you would any URL (like a web link). Be sure to ask before opening Keyboard settings.

Swift

Listing 2  Opening Keyboard settings (Swift).

let keyboardSettingsURL = NSURL(string: "prefs:root=General&path=Keyboard")
UIApplication.sharedApplication().openURL(keyboardSettingsURL!)

Objective-C

Listing 3  Opening Keyboard settings (Objective-C).

 NSURL *keyboardSettingsURL = [NSURL URLWithString: @"prefs:root=General&path=Keyboard"];
 [[UIApplication sharedApplication] openURL:keyboardSettingsURL];

HTML

Listing 4  Opening Keyboard settings (HTML).

<a href="prefs:root=General&path=Keyboard">Open Keyboard settings</a>


Document Revision History


DateNotes
2016-08-02

New document that describes how to open the Keyboard settings from your iOS keyboard extension, making it easier for users to enable your extension.