如何在Swift中禁用第三方键盘?

时间:2016-01-18 20:14:20

标签: ios swift uikeyboard

基本就是这样,我还没有找到一种方法来禁用我的应用程序中的第三方键盘,虽然我知道这可能是因为我在1Password等应用程序中看到它。

有什么想法吗?

5 个答案:

答案 0 :(得分:13)

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

答案 1 :(得分:9)

斯威夫特3:

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

    return true
}

答案 2 :(得分:3)

Swift 4.2

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

答案 3 :(得分:1)

Swift 5.0

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

答案 4 :(得分:0)

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
  return extensionPointIdentifier != .keyboard
}