Integrating In-App Keyboard

There are use cases where the developers need a custom keyboard only for specific text fields within their app. In this case, having a system-wide keyboard is overkill and not a desired solution.

To mitigate this issue, Fleksy Keyboard SDK supports integrating as an in-app keyboard without needing a system-wide keyboard. This way, the developers can use the SDK-backed keyboard only for specific text fields inside their app.

On iOS, in any field of your app, you can replace the system-provided keyboard with a custom input view. In particular, with the in-app keyboard. For more information, please check the official Apple documentation.

In-App Keyboard for iOS

Initial Setup

To integrate in-app keyboard within an app, there are two possible ways to get started, i.e., either with a custom keyboard extension or without one.

Without Custom Keyboard Extension

To use the SDK, please note that you first need a license key which can be requested in the developer’s dashboard.

To integrate the Fleksy Keyboard SDK as in-app keyboard without creating a system wide keyboard (using custom keyboard extension), follow the following steps:

  1. Create a new class (for e.g. KeyboardViewController), import the FleksyKeyboardSDK package and inherit from FKKeyboardViewController.
  2. Override the method createConfiguration to return a configuration as shown below.
  3. Finally replace <your-license-key> and <your-license-secret> with your license.
It is recommended NOT to commit your license keys in the code but to store them as variables in the environment and access them during the compilation.
import FleksyKeyboardSDK

class KeyboardViewController: FleksyKeyboardSDK.FKKeyboardViewController {

    override func createConfiguration() -> KeyboardConfiguration {

        let licenseConfig = LicenseConfiguration(
            licenseKey: "<your-license-key>",
            licenseSecret: "<your-license-secret>"
        )

        return KeyboardConfiguration(
            license: licenseConfig
        )
    }
}

Once done, we can use this class to access the Fleksy Keyboard SDK as an in-app keyboard either via UIRsponder’s Subclass or by Using TextField’s or TextView’s inputView with our custom input views as required.

With Custom Keyboard Extension

This step builds upon the initial setup guide. If you still need to do the initial setup, please check out the instructions for the iOS platform before proceeding further.

In case a developer wishes to integrate to integrate the in-app keyboard with the custom keyboard extension, they can use the same FKKeyboardViewController subclass (i.e., KeyboardViewController) created during the initial setup guide for the keyboard extension as an in-app keyboard. However, first we need to add it to the app’s target.

To add the class to the app’s target, check out the Target Membership section in the File Inspector pane. Ensure both the app and keyboard extension are selected.

Target Membership

Afterward, there are two possible ways to have the custom keyboard as an in-app keyboard in the app listed below.

Via UIResponder’s Subclass

As pointed out in the official Apple documentation, we can override the inputViewController: UIInputViewController? property of UIResponder in its subclass. In the overridden inputViewController property, we can return your custom KeyboardViewController whose input view we want as an in-app keyboard.

For Example

The following example reflects how to do this for a UITextField subclass.

import UIKit

class CustomTextField: UITextField {
  
    private let keyboardViewController = KeyboardViewController()
    
    override var inputViewController: UIInputViewController? {
        return keyboardViewController
    }
}

The same can be done for any other UIResponder subclass (e.g., UITextView).

Using TextField’s or TextView’s inputView

If using a subclass of UIResponder is not preferred, we can change the inputView of any UITextField or UITextView to the one we want. In particular, we can change it to our in-app keyboard’s inputView.

For Example

Ensure to keep a strong reference to the KeyboardViewController; otherwise, unexpected behaviors can happen with the in-app keyboard.

The following example reflects how to do this for a UITextField subclass.

class ViewController: UIViewController {
    @IBOutlet weak var textField: UITextField!
    
    // IMPORTANT: keep a strong reference to the KeyboardViewController
    private let keyboardViewController = KeyboardViewController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.textField.inputView = self.keyboardViewController.inputView
    }
}

The same can be done for any other UIResponder subclass (e.g., UITextView).

Additional Resources

For more information on working with themes, consider checking out the API reference documentation, which documents all the available methods to customize the keyboard built with Fleksy Keyboard SDK.


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on February 20, 2024