iOS: Password Autofill and Suggestions
3 minute read
About Password Autofill
iOS 11+ introduces Password Autofill and Suggestions like Safari accessing them from keychain using apple-app-site-association
.
You can now enable your apps to suggest the specific credentials at your login screen to reduce login delays and forgotten or mistyped passwords and usernames.
Pre-requisites:
- iOS 11+
- Xcode 9
- Paid Apple Developer Account
- Write Access to your domain server e.g eopio.com
Steps:
Using Code:
usernameTextField.textContentType = .username passwordTextField.textContentType = .password
Using Storyboard:
Open your iOS project in Xcode and:
Username
Set the Username TextField Content Type
to Username
as shown in the below.
Password
Set the Password TextField Content Type
to Password
as shown.
Associated Domain
- Go to Project Navigator and Select your Project Root.
- From the Editing Area, Select
Capabilities
tab - Scroll down to
Associated Domains
and - Toggle the
ON
Switch - Replace example.com to your auth domain e.g eopio.com - you can find your domain name in keychain access.
- Double-check the steps here to make sure all is configured correctly. Usually the step
Add the Associated Domains feature to your App ID.
is a possible issue here.
Possible Build Error Here (1):
This means you’re Xcode Signing is not using a Paid Apple Developer Account.
Solution: Just use your paid Developer Account for Xcode Code Signing.
Possible Error Here (2):
This Error Means that
Associated Domains
Feature is Disabled for this app id
in the your Developer Portal
Suolution: Follow the steps below to fix it.
Adding Associated Domains Feature to App ID.
- Login to your Apple Developer Portal https://developer.apple.com/account
- From the left panel, Select
Certificates, IDs & Profiles
-
Select
App IDs
from the Left Panel again. -
Select your
app id
orname
from the list of registered apps. Xcode automatically registers your apps as soon as you configure Signing.If your
app id
is not in the list, 1 Check Xcode Signing configuration for your project. 2 If Signing is correct, then Register your App following these steps Register App ID on Apple Developer Portal
Prefix (2): is the Team ID
. Take note for we’ll need it later.
ID (3): is the app id
also same as Bundle Identifier
set in Xcode. Also note this one.
- Read throgh the List of Services currently enabled for your
app id
IfAssociated Domains
(4) is Disabled, click Edit (5) and Check next to Associated Domains to Enable it.
Simple Server Side Configuration
Using text-editor of your preference,
- Create a file named
apple-app-site-association
with the following JSON content:
{
"webcredentials": {
"apps": [ "apple_team_id.app_bundle_id" ]
}
}
Replace:
apple_team_id
with your Apple Developer Team ID.
app_bundle_id
with your App’s Bundle ID
You can find your Team ID and App’s Bundle ID from the section above on Adding Associated Domains Feature to App ID.
-
Copy file
apple-app-site-association
to your web server root or to.well-known
directory in your web server root. -
Edit your web server config to return the JSON content.
For NGINX, use the settings below:
# if file is in webroot
location /apple-app-site-association {
default_type application/json;
}
# if file is in .well-known directory
location /.well-known/apple-app-site-association {
default_type application/json;
}
Restart your webserver. For NGINX on Ubuntu: service nginx restart
Verify that the JSON content is being served on your domain loading either yourdomain/apple-app-site-association
or yourdomain/.well-known/apple-app-site-association
depending on which directory you added the file apple-app-site-association.
Build and Run your application.
Good Luck and Let me know :-D