Logo for tanaschita.com

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.

Sponsorship logo
Using Proxyman to inspect network traffic
Proxyman is a native debugging proxy that can act as a man-in-the-middle between your application and web server. You can use its powerful toolkit to inspect network calls and debug your application on Mac, iOS Simulator, or remote devices effortlessly.
CLICK TO LEARN MORE

To activate Password Autofill in an iOS application, the following steps are required:

  1. Setting up the app's associated domains.
  2. 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:

  1. Creating and configuring an associated domain file for shared web credentials.
  2. Adding the associated domain file to the related website.
  3. 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:

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 = .username
userTextField.keyboardType = .emailAddress
passwordTextField.textContentType = .password
Sponsorship logo
Using Proxyman to inspect network traffic
Proxyman is a native debugging proxy that can act as a man-in-the-middle between your application and web server. You can use its powerful toolkit to inspect network calls and debug your application on Mac, iOS Simulator, or remote devices effortlessly.
CLICK TO LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

associated domains

security

ios

Supporting universal links in a SwiftUI application

Learn how to implement universal links to be able to link to content in the iOS application and its connected website.

01 Aug 2022 · 3 min read

Latest articles and tips

© 2022 tanaschita.com

Privacy policy

Impressum