Set a PasswordField to secureTextEntry give me a strange behaviour
Asked Answered
C

7

33

I have a passwordField for which I set the isSecureTextEntry to true to hide the characters. But when I click on this passwordField, the following error appears in the log:

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

and the keyboard automatically changes from azerty to qwerty...

If I remove the passwordField.isSecureTextEntry = true, the problem disappears, but the character are not hidden...

Here's my code :

passwordField.borderStyle = UITextField.BorderStyle.none
passwordField.font = UIFont(name: "Avenir-Heavy", size: 13)
passwordField.autocorrectionType = UITextAutocorrectionType.no
passwordField.clearButtonMode = UITextField.ViewMode.whileEditing
passwordField.keyboardType = UIKeyboardType.default
passwordField.returnKeyType = UIReturnKeyType.done
passwordField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.bottom
passwordField.isSecureTextEntry = true

I tested this answer but nothing changed.

How can I hide the character of my textField without iCloud Keychain and without change of keyboard to qwerty?

I checked other answers, but nothing is similar to my problem...

Crypt answered 12/10, 2018 at 0:26 Comment(1)
You can ignore the warning (or enable iCloud keychain on your device). I believe that the QWERTY keyboard issue is a known bug with a potential work-aroundShaunteshave
C
13

This happens when the system's user doesn't have iCloud Keychain enabled. As will often be the case on the Simulator :)

I ran into this on the simulator and came here. Tried it on my phone (where iCloud Keychain is enabled), and got this instead:

[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: your.bundle.id due to error: Cannot save passwords for this app. Make sure you have set up Associated Domains for your app and AutoFill Passwords is enabled in Settings

So this is Apple's cool AutoFill feature. There are some steps described here that should enable that.

Caduceus answered 14/10, 2019 at 19:35 Comment(3)
This is the correct answer to the question. The error message in the question relates to whether the device has iCloud Keychain enabled or not. Nothing to do with the code.Holliman
Great answer @DarrenTala
iCloud Keychain enabled but still, I m getting this errorPomposity
C
11

In our case we had another text field on same screen with content type Email Address, changing that to Username magically solved the problem.

Coating answered 13/8, 2019 at 16:38 Comment(1)
I think this is because UITextContentType.username and UITextContentType.newPassword are part of AutoFill's heuristics. If your app is using an email as a username, then Apple suggests setting the text field's textContentType to .username and keyboardType property to .emailAddress. See: developer.apple.com/documentation/security/password_autofill/…Andrewandrewes
N
4

You are probably using the wrong Team ID in your association file. The Team ID is NOT the one yo usee under "signing Certificate" on XCode. To check your team ID go to your ACCOUNT on https://developer.apple.com/ , under membership. That should solve it. I was using the wrong Team ID and was stuck with the same issue.

With the fix above, just follow this: https://robopress.robotsandpencils.com/strong-passwords-in-ios-12-8ec819b3b99

Nevile answered 28/1, 2019 at 4:55 Comment(1)
What you are saying is correct but I don't think it has anything todo with the error: iCloud Keychain is disabled message.Coating
C
4

I was having same issue while i was running my application on the simulator. Setting autocorrection to no solved my issue. I hope it helps you.

textFieldPassword.autocorrectionType = .no
Cloying answered 23/1, 2020 at 5:7 Comment(1)
This worked for me after adding: field.textContentType = .noneZyrian
C
3

in my case: I have 4 fields (username-email-pass-confirm pass) and when the user tap on password or confirm password fields the keyboard return that error and show a strong password suggestion and don't let to change the password field text.

solution: I changed all fields Content type to (One Time Code) and just set (Secure Text Entry = true) in the password and confirm password fields.

Curdle answered 18/11, 2020 at 20:35 Comment(1)
My problem was that I did not want "Passwords…" autofill prompts to begin with since the secure text entry fields are never saved to the keychain. I wanted to suppress such behavior. Setting "Content Type" to "One Time Code" solved it for me.Relax
W
0

Automatic Strong Passwords :- Enable iCloud Keychain

Automatic Strong Passwords suggestion works if user has enabled the iCloud keychain in its iPhone.

I was able to solved by these following steps:-

  • Go to the Setting
  • Tap on UserName (Apple Id)
  • Tap on iCloud
  • Tap on keychain
  • Enable iCloud Keychain
Wordless answered 19/6, 2020 at 6:23 Comment(0)
S
0

I borrowed @Hamid Reza Ansari's answer above, but also had to support older iOS versions, so wrapped it in a condition:

if #available(iOS 12.0, *) {
    self.textContentType = .oneTimeCode
}
Spatter answered 2/12, 2020 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.