Native UITextField Secure Text Entry forces English (US) keyboard

China☆狼群 提交于 2019-11-30 03:19:29

I have the same issue, in my case this bug appears only with a register screen.

The reason is that Apple checks the name of the class/func/parameter to determine (with heuristics) if it is a login/register screen and activate automatically autofill password. By replacing "register" with "Patate" in my code, the problem is solved.

I reproduce this issue with a sample app with 2 textfields (with a security text entry) and a view controller named "RegisterViewController". With a "PatateViewController", I have not the issue.

Moreover, I have this error in console : [AutoFill] Cannot show Automatic Strong Passwords for app bundleID: *** due to error: iCloud Keychain is disabled

Source : https://developer.apple.com/documentation/security/password_autofill

Hope you will find a better way than renaming your code.

I had the same problem appear recently on our application. The problem is linked to the new feature of the PasswordAutofill from Apple.

To bypass this problem you can apply this little piece of code on your secure textfield

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

This should resolve this bug. This should also fix this error:

[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: *** due to error: iCloud Keychain is disabled

Ps: You could also add this new feature to your app. This is a link to an article explaining the process on how to implement this new feature Explanation on how to implement password autofill

Hope it helps.

Had the same problem and solved it by setting all my textFields textContentType property to UITextContentType.oneTimeCode.

Of course, oneTimeCode is now useless since it's everywhere...

Swift 3:

Create base class for UITextField with languageCode and textInputMode.

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;
}}

Usage:

Set your value (ru, en, ...) to languageCode. It will force change the locale in the keyboard.

private func textConfigure(textField: UITextField) {

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

Hope help you.

This was truly an iOS bug => corrected in iOS 12.1

iOS 12.1 fixed the problem for me.

You also have to set the parameter textContentType of the password textfield to .oneTimeCode

The lamer a bug is, the lamer the solution should be, i mean what a lame work by Apple.

My solution was to force a focus on the password field and then focus on the first field, in my case it was the usernameField.

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.passwordTextField becomeFirstResponder];
    [self.usernameTextField becomeFirstResponder];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!