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.

Setup

To integrate in-app keyboard within an app, follow the next steps.

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.
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.

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