February 20, 2020

Preventing custom Keyboards in your iOS App

Starting with iOS Version 8.0 Apple started supporting custom Keyboards. They enable to expose unique keyboard functionality system wide. For instance before implementing it themselves one could use the SwiftyKey custom Keyboard to have faster and better input through swiping.

In some cases though it would be beneficial for an app to disable custom Keyboards for input. This is achieved by implementing the following function in your AppDelegate.swift file

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool

This function is used to ask the application which app extensions are allowed to use. This is done through specific extension point identifiers. (If you don't implement this method all app extensions are allowed for use in your app). For custom Keyboards this identifier is

UIApplication.ExtensionPointIdentifier.keyboard

So to disable the use of custom Keyboards in the App one could do the following

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
    if extensionPointIdentifier == UIApplication.ExtensionPointIdentifier.keyboard {
        return false
    } else {
        return true
    }
}

Or shorter

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
    return extensionPointIdentifier != UIApplication.ExtensionPointIdentifier.keyboard
}
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket