# How to disable custom keyboards in iOS SwiftUI-based applications

In this blog post, I explain how you can prevent users from using custom keyboards in your iOS applications developed with SwiftUI.

Preventing custom keyboards is a common security requirement for mobile enterprise applications. More on Android than iOS, but it is good to know how to disable it if a product owner asks.

Custom keyboards are [app extensions](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214). If you want to learn how to create a custom keyboard and how to test it, then I recommend reading [Create custom keyboards in iOS](https://levelup.gitconnected.com/custom-keyboards-in-ios-affb62668d48) by David Martinez.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1671472983494/K36NQbmBY.webp align="center")

UIKit provides the [application(\_:shouldAllowExtensionPointIdentifier:)](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623122-application) function on the `UIApplicationDelegate` protocol to grant or deny permission to use specific app extensions, particularly [keyboard](https://developer.apple.com/documentation/uikit/uiapplication/extensionpointidentifier/1623024-keyboard).

Implement the function in a custom class, then use your class with the `UIApplicationDelegateAdaptor` property wrapper in your SwiftUI app.

```swift
@main
struct MySwiftUIApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
        switch extensionPointIdentifier {
        case UIApplication.ExtensionPointIdentifier.keyboard:
            return false
        default:
            return true
        }
    }
}
```

The function gets called every time your user sets or removes the focus to a `TextField` .

By implementing [application(\_:shouldAllowExtensionPointIdentifier:)](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623122-application) the user can be prevented from using custom keyboards, as those are not listed anymore within the iOS app.

![No more custom keyboard selection](https://cdn.hashnode.com/res/hashnode/image/upload/v1672707335502/e96632f2-7f85-471f-a1a3-e19af9e5faac.gif align="center")

Without the implementation, the user was able to choose any custom keyboards as demonstrated here:

![Custom Keyboard selection](https://cdn.hashnode.com/res/hashnode/image/upload/v1672707311309/da50893e-ba13-48c6-b2c1-d47f87b03c72.gif align="center")
