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

问题描述 投票:0回答:5

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

有什么想法吗?

ios swift uikeyboard
5个回答
23
投票

将此代码添加到您的

AppDelegate

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

斯威夫特4:

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

斯威夫特5

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

苹果参考


9
投票

斯威夫特 3 :

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

    return true
}

5
投票

斯威夫特4.2

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

3
投票

Swift 5.0 中

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

2
投票
func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
  return extensionPointIdentifier != .keyboard
}
© www.soinside.com 2019 - 2024. All rights reserved.