How to disable custom keyboards for iOS application using Swift

Recently I was working on an iOS application that allowed users to enter sensitive data. For such a situation, one of the recommendations from MASVS (Mobile Application Security Verification Standard) is to disable custom third-party keyboards (MSTG-PLATFORM-11).
Fortunately, on iOS, this is super simple. All we have to do is add the following code to the AppDelegate:

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
    switch extensionPointIdentifier {
    case UIApplication.ExtensionPointIdentifier.keyboard: return false
    default: return true

That's it. From now on, every time a keyboard appears on the screen, the delegate method is called and disables custom 3rd party keyboards.


Anything interesting to share? Write a comment.