Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoFill username and password in iOS 12

I implemented AutoFill for stored username and password suggestion successfully in iOS 11.
I have two text fields in my login view controller, one for email, one for password. The content types are defined as follows:


email / username text field configuration


password text field configuration

This used to work just fine in iOS 11, but after upgrading my development iPad to iOS 12, the app suggests emails for the username field and the following happens when editing the password field:


In my create account view controller, I have 3 text fields: email, password, repeat password. Their content modes are setup as follows:

  • email → email address
  • password → new password, rule: minlength:8;
  • repeat password → new password, rule: minlength:8;

When editing the email address field, it properly suggests an email address. For the password and repeat password fields, however, it suggests stored passwords, instead of suggesting a new password.


What I tried

  • (illogically) flip the content mode setup, so the login password field is set to new password and the create account password fields are set to password
    • no success; in fact, no change of behavior at all
  • set content mode to none for login and create account fields so AutoFill can try to handle it automatically
    • no success; in fact, no change of behavior at all

Note

  • AutoFill is properly setup on the server. The stored passwords being suggested in the create account fields prove that
  • The functionality is still working on iOS 11 iPads
  • When logging in with a new username, the app will ask the user to add this username and password to Keychain, even on iOS 12

Any idea what I need to change so that stored username & password suggestion works in iOS 12 again?

Thanks!



Edit

As requested by @kralex below, here's my view hierarchy for the login view controller in the storyboard:

...and on the device:

like image 614
LinusGeffarth Avatar asked Sep 26 '18 09:09

LinusGeffarth


2 Answers

Apple is doing some heuristic to make the best guess what you might need: autofill or a new password. However in some cases it might fail.

In your case the problem is related to the "Create Account Button". It makes the system think that it is a sign up form.

The easiest option to fix it: replace sign up UIButton with UILabel and add tapRecognizer to handle taps.

like image 90
alxndr Avatar answered Oct 22 '22 23:10

alxndr


I had a similar issue and found out Apple's heuristics were tapping in to the class name of the view controller to determine whether to suggest a new password or use an existing one. It seems like even if I set the correct textContentType on my UITextFields, it still would use the name of the controller.

My UIViewController has both sign up and login on the same screen, but the controller is named RegistrationViewController. I changed it to LoginViewController to test, and found that the login portion started working, but the registration bit acted like it was login! Even with the correct textContentTypes set!

I wound up having to rename my UIViewController something that doesn't imply registration or login for it to actually respect my textContentTypes. It's awful. Truly awful.

I would imagine at least part of the reason this is/was happening to you is because the you have the word Welcome as the beginning of your view controller, unbelievable as it sounds.

By the way, I tried RegistrationLoginViewController (it chose the registration setup) and LoginRegistrationViewController (it chose the login setup), and neither worked. It has to avoid Apple's heuristics if you want to have both on the same controller.

like image 41
Stakenborg Avatar answered Oct 22 '22 21:10

Stakenborg