Article

Enabling Password AutoFill on a Text Input View

Ensure a text input view displays the correct AutoFill suggestions.

Overview

To ensure your text input view displays the right AutoFill suggestions, set the textContentType property on any relevant input views.

Use the following UITextContentType values:

Credential

UITextContentType Value

User Name

.UITextContentTypeUsername

Password

.UITextContentTypePassword

New Password

.UITextContentTypeNewPassword

One-Time Code

.UITextContentTypeOneTimeCode

Explicitly defining a view’s text content type improves the performance of Password AutoFill’s heuristics and lets you support login workflows that couldn’t otherwise be detected by these heuristics. For example, the heuristics assume the user name and password inputs are on the same page. If you have a multipage login form, explicitly setting the .username and .password types lets the user tap and fill those inputs, even if they are on separate pages.

By default, the system selects the a keyboard based on the input view’s textContentType property; however, you can mix the input view’s text content type and keyboard type to explicitly define the desired keyboard. For example, if your site uses email addresses as user names, set the input view’s textContentType property to .UITextContentTypeUsername, and set the keyboardType property to .UIKeyboardTypeEmailAddress.

This example defines text fields for logging in:

userTextField.textContentType = .username
userTextField.keyboardType = .emailAddress
passwordTextField.textContentType = .password

When creating a new account or changing the password, use the .UITextContentTypeNewPassword text content type instead:

newPasswordTextField.textContentType = .newPassword
confirmPasswordTextField.textContentType = .newPassword

Additionally, you can autocomplete security codes from single-factor SMS login flows:

singleFactorCodeTextField.textContentType = .oneTimeCode

iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol.

For more information on how to enable Password AutoFill behavior in web apps, see Enabling Password AutoFill on an HTML Input Element.

See Also

Modifying Text Input Views

textContentType

Indicates the semantic meaning expected by a text-entry area.

UITextContentTypeUsername

Specifies the expectation of an account or login name.

UITextContentTypePassword

Specifies the expectation of a password.

UITextContentTypeNewPassword

Specifies the expectation of a new password.

UITextContentTypeOneTimeCode

Specifies the expectation of a single-factor SMS login code.