Native UITextField Secure Text Entry forces English (US) keyboard

后端 未结 10 1944
离开以前
离开以前 2020-12-13 19:19

I have a very simple login page (login + password).

My users are french, so their keyboard are French (azerty).

Since iOS 12, when they click on the password

相关标签:
10条回答
  • 2020-12-13 19:31

    I had the same issue in React Native when I set the keyboardType to "numeric-pad". It's a native IOS issue due to default language set in info.plist file.

    I found the solution here : https://github.com/facebook/react-native/issues/27972

    Delete these 2 lines to unset the default language :

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

    You could also just modify <string>en</string> to <string>fr</string> but then you will have the same issue with english users who will have a switch to azerty keyboard :/

    0 讨论(0)
  • 2020-12-13 19:32

    Same solution in Swiftui now :

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

    just need to add :

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

    to a TextField or a SecureField.

    hope it helps !

    0 讨论(0)
  • 2020-12-13 19:32

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

    0 讨论(0)
  • 2020-12-13 19:35

    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];
    }
    
    0 讨论(0)
  • 2020-12-13 19:37

    Just in case, I corrected this by simply adding this to my main viewController :

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

    And I created the subclass of 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
        }
     }
    }
    
    0 讨论(0)
  • 2020-12-13 19:43

    iOS 12.1 fixed the problem for me.

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

    0 讨论(0)
提交回复
热议问题