How does one disable third party keyboards in Swift?

前端 未结 5 418
半阙折子戏
半阙折子戏 2020-12-16 19:35

Basically that\'s it, I haven\'t found a way to disable third party keyboard in my app, although I know it\'s possible \'cos I\'ve seen it in apps like 1Password.

An

相关标签:
5条回答
  • 2020-12-16 19:53

    In Swift 5.0

      func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
        return extensionPointIdentifier == UIApplication.ExtensionPointIdentifier.keyboard ? false : true
      }
    
    0 讨论(0)
  • 2020-12-16 19:55
    func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
      return extensionPointIdentifier != .keyboard
    }
    
    0 讨论(0)
  • 2020-12-16 19:56

    Add this code in your AppDelegate

    func application(application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: String) -> Bool {
        if extensionPointIdentifier == UIApplicationKeyboardExtensionPointIdentifier {
            return false
        }
        return true
    }
    

    Swift 4:

    func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
        if extensionPointIdentifier == UIApplicationExtensionPointIdentifier.keyboard {
            return false
        }
        return true
    }
    

    Apple reference.

    0 讨论(0)
  • 2020-12-16 19:57

    Swift 4.2

    func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
        if extensionPointIdentifier == UIApplication.ExtensionPointIdentifier.keyboard {
            return false
        }
        return true
    }
    
    0 讨论(0)
  • 2020-12-16 20:07

    Swift 3 :

    func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
        if extensionPointIdentifier == UIApplicationExtensionPointIdentifier.keyboard {
            return false
        }
    
        return true
    }
    
    0 讨论(0)
提交回复
热议问题