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.
To integrate in-app keyboard within an app, follow the next steps.
To integrate the Fleksy Keyboard SDK as in-app keyboard without creating a system wide keyboard (using custom keyboard extension), follow the following steps:
KeyboardViewController
), import the FleksyKeyboardSDK
package and inherit from FKKeyboardViewController.createConfiguration
to return a configuration as shown below.<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.
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
).
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
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
).
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.