本机UITextField安全文本输入会强制使用英语(美国)键盘

时间:2018-10-08 11:21:08

标签: ios swift keyboard uitextfield

我有一个非常简单的登录页面(登录名和密码)。

我的用户是法语,所以他们的键盘是法语(azerty)。

从iOS 12开始,当他们单击安全的密码文本字段时,即使他们的设备上未安装此键盘,键盘也会切换为英语(qwerty)。而且,如果他们没有安装此键盘,则无法切换回键盘。

我发现,如果我停用“安全文本输入”,则不会出现该问题。

我还尝试以编程方式设置isSecureTextEntry,并且该错误显示出来。

我要添加两个屏幕截图,每个文本字段一个。

非常感谢您的时间和帮助。

enter image description here

enter image description here

11 个答案:

答案 0 :(得分:6)

我有同样的问题,就我而言,此错误仅在注册屏幕上出现。

原因是Apple检查类/函数/参数的名称,以确定(具有启发式)它是否是登录/注册屏幕,并自动激活自动填充密码。 通过在我的代码中将“ register”替换为“ Patate”,问题得以解决。

我使用具有2个文本字段(带有安全性文本输入)和名为“ RegisterViewController”的视图控制器的示例应用程序来重现此问题。使用“ PatateViewController”,我没有问题。

此外,我在控制台中遇到此错误: [自动填充]由于错误:无法禁用iCloud钥匙串,因此无法显示应用程序包ID:***的自动强密码

来源:https://developer.apple.com/documentation/security/password_autofill

希望您会发现比重命名代码更好的方法。

答案 1 :(得分:3)

我最近在我们的应用程序中出现了同样的问题。 该问题与Apple的 PasswordAutofill 的新功能有关。

要绕过此问题,您可以在安全文本字段上应用此小段代码

    if #available(iOS 12.0, *) {
        tfPassword.textContentType = .oneTimeCode
    }

这应该可以解决此错误。 这也应该解决此错误:

  

[自动填充]由于错误:iCloud钥匙串已禁用,因此无法显示应用程序包ID:***的自动强密码

Ps:您也可以将此新功能添加到您的应用中。 这是指向文章的链接,该文章解释了有关如何实现此新功能的过程 Explanation on how to implement password autofill

希望有帮助。

答案 2 :(得分:2)

遇到相同的问题,并通过将 all 我的textFields textContentType属性设置为UITextContentType.oneTimeCode来解决。

当然,oneTimeCode现在无处不在,因为它无处不在...

答案 3 :(得分:2)

Swiftui中现在有相同的解决方案:

TextField("placeholder",text: $YourTextBinding)
                        .textContentType(.oneTimeCode)
                        .keyboardType(.default)

只需添加:

                        .textContentType(.oneTimeCode)
                        .keyboardType(.default)

TextFieldSecureField

希望有帮助!

答案 4 :(得分:2)

当我将keyboardType设置为“ numeric-pad”时,我在React Native中也遇到了同样的问题。 由于info.plist文件中设置了默认语言,这是IOS的固有问题。

我在这里找到了解决方法:https://github.com/facebook/react-native/issues/27972

删除这两行以取消设置默认语言:

<key>CFBundleDevelopmentRegion</key>
<string>en</string>

您也可以只将<string>en</string>修改为<string>fr</string>,但是对于英语用户,您将遇到同样的问题,他们将切换到azerty键盘:/

答案 5 :(得分:1)

快速3:

使用languageCode和textInputMode为UITextField创建基类。

class BaseTextField: UITextField {

// ru, en, ....
var languageCode: String? {

    didSet{

        if self.isFirstResponder{

            self.resignFirstResponder();
            self.becomeFirstResponder();
        }
    }
}

override var textInputMode: UITextInputMode? {

    if let language_code = self.languageCode {

        for keyboard in UITextInputMode.activeInputModes {

            if let language = keyboard.primaryLanguage {

                let locale = Locale.init(identifier: language);
                if locale.languageCode == language_code {

                    return keyboard;
                }
            }
        }
    }

    return super.textInputMode;
}}

用法:

将您的值(ru,en,...)设置为languageCode。它将强制更改键盘上的语言环境。

private func textConfigure(textField: UITextField) {

    textField.keyboardType = .default
    textField.autocapitalizationType = .words
    textField.languageCode = "ru"
}

希望可以帮助您。

答案 6 :(得分:0)

这确实是一个iOS错误=>在iOS 12.1中已得到纠正

答案 7 :(得分:0)

iOS 12.1为我解决了这个问题。

您还必须将密码文本字段的参数textContentType设置为.oneTimeCode

答案 8 :(得分:0)

错误是错误的,解决方案应该是错误的,我的意思是苹果公司的行事me脚。

我的解决方案是强制将重点放在密码字段上,然后再将焦点放在第一个字段上,在我的情况下,这是usernameField。

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.passwordTextField becomeFirstResponder];
    [self.usernameTextField becomeFirstResponder];
}

答案 9 :(得分:0)

以防万一,我只是通过将其添加到我的主viewController中来纠正了这个问题:

func passwordSignUpViewController(forAuthUI authUI: FUIAuth, email: String, requireDisplayName: Bool) -> FUIPasswordSignUpViewController {
    return CustomPasswordSignUpViewController(authUI: authUI, email: email, requireDisplayName: true)
}

然后我创建了FUIPasswordSignUpViewController的子类

import Foundation
import FirebaseUI

class CustomPasswordSignUpViewController : FUIPasswordSignUpViewController, UITextFieldDelegate {

 override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, authUI: FUIAuth, email: String?, requireDisplayName: Bool) {
    super.init(nibName: "FUIPasswordSignUpViewController", bundle: nibBundleOrNil, authUI: authUI, email: email, requireDisplayName: requireDisplayName)        
 }

 required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
 }

 override func viewDidLoad() {
    super.viewDidLoad()
 }

 func textFieldDidBeginEditing(_ textField: UITextField) {
    if #available(iOS 12.0, *) {
        textField.textContentType = .oneTimeCode
    }
 }
}

答案 10 :(得分:0)

就我而言,以下行解决了我的问题。

textField.textContentType = .newPassword