Implementing Password AutoFill for an iOS application
Learn how to activate Apple's Password AutoFill for SwiftUI and UIKit.
15 Aug 2022 · 3 min read
Apple's Password AutoFill feature allows users to login into the same account on different devices without having to remember their credentials.
For example, when signing up in a web app, users are able to generate a password and to save credentials in their iCloud keychain. When they run a native app to access the same account at some point, the app suggests the credentials stored for the website in the password QuickType bar. After the user authenticates, let's say by using Face ID, the system prefills the credentials - so there is no need to reenter them.

To activate Password Autofill in an iOS application, the following steps are required:
- Setting up the app's associated domains.
- Setting the correct AutoFill type on relevant text fields.
Let's look at those steps in more detail.
Setting up the app's associated domains for shared web credentials
Associated domains establish a secure association between a website and an iOS application. To support shared web credentials, the following steps are required:
- Creating and configuring an associated domain file for shared web credentials.
- Adding the associated domain file to the related website.
- Adding an associated domain entitlement to the iOS app.
Each of those steps is described in more detail in this quide on associated domain files.
Enable Password Autofill with textContentType
After setting up shared web credentials, all we need to do is to set the textContentType property on any relevant input views to activate the correct AutoFill suggestions.
The following UITextContentType values are available:
- .username for account names
- .password for passwords
- .newPassword for new passwords
- .oneTimeCode for one-time passwords, for example to autocomplete security codes from single-factor sms login flows
Let's see how to do that for SwiftUI and UIKit applications.
Enable Password Autofill for SwiftUI
In SwiftUI, we can set a UITextContentType value by using the textContentType(_:) method:
TextField("Enter your email", text: $emailAddress).textContentType(.username).keyboardType(.emailAddress)TextField("Enter your password", text: $password).textContentType(.password)
Based on textContentType we provided, iOS automatically chooses a matching keyboard to show to the user.
To present a different keyboard, for example if the app uses emails as user names, we can additionally set the .keyboardType to a desired value.
Enable Password Autofill for UIKit
UIKit supports Password AutoFill on UITextField, UITextView and any custom view that adopts the UITextInput protocol. We can set a UITextContentType value by using the textContentType instance property:
userTextField.textContentType = .usernameuserTextField.keyboardType = .emailAddresspasswordTextField.textContentType = .password

Newsletter
Like to support my work?
Say hi
Related tags
Articles with related topics
Latest articles and tips