contact Us
whatsapp icon
Safari Autofill Password Brilliant New Feature in iOS
Mobile App Development

Safari Autofill Password Brilliant New Feature in iOS

Written By

Nikhil Solanki

Mobile Lead at Manek Tech

Updated

April 24, 2024

Read

2 Min

Table of Contents

That stores your password and allows you to log in using those credentials in the future. 

Benefits:- AutoFill simplifies the login and account creation for your app. The system will be handling auto-filling the user’s password in case of login or generating unique and strong passwords when creating an account. The main benefit is that the users don’t even need to remember their password since the system handles everything. Additionally, auto-generating strong passwords will increase the security of your app. User data is saved in the user’s device and is synced to the iCloud keychain and will be available to all the devices using the same iCloud.

How to enable autofill?

Just set the textContentType for each Textfield.
txtUserName.textContentType = .username
txtPassword.textContentType = . password

 

App Id Creation and Enable Associated Domain: -
First, start with the creation of an app in the Apple Developer Centre with Enable “Associated Domains” and “AutoFill Credential Provider”.

App Id Creation and Enable Associated Domain

After creating an App ID, create a Provision profile for that App ID and you are ready to use that in your XCode project.
XCode Project Setup: -

Step 1: - Enable Associated Domain and Autofill Credential provider in your Project Capabilities Section

Associated Domain is used to store your credentials for that particular Domain or you can add multiple domains in that section.

using system

Step 2: - Server-Side Coding

2.1) Create an apple-app-site-association file on your server and create that JSON file

echo ‘{“webcredentials”:{“apps”:[“AppID Prefix.com.YourBundleID”]}}’ > json.txt

system

Step 3: - Coding

3.1) Create a function to store your credentials with domain

class func updateSafariCredentials(username: String, password: String) {

let domain: CFString = "example.com" as CFString

SecAddSharedWebCredential(domain, username as CFString, password as CFString) { (error) in
print(error ?? "")
}}

This method will open a Popup menu in order to ask for the permission of saving the password and your password will be saved in the iCloud keychain.

coding

3.2) Retrieve Saved password

This method will retrieve your saved password.

class func checkSafariCredentialsWithCompletion(completion: @escaping ((_ username: String?, _ password: String?) -> Void)) {

let domain: CFString = "example.com" as CFString

SecRequestSharedWebCredential(domain, .none, {
(credentials: CFArray!, error: CFError?) -> Void in

if let error = error {
print("error: (error)")
completion(nil, nil)
} else if CFArrayGetCount(credentials) > 0 {
let unsafeCred = CFArrayGetValueAtIndex(credentials, 0)
let credential: CFDictionary = unsafeBitCast(unsafeCred, to: CFDictionary.self)
let dict: Dictionary<String, String> = credential as! Dictionary<String, String>
let username = dict[kSecAttrAccount as String]
let password = dict[kSecSharedPassword as String]
DispatchQueue.main.async {
completion(username, password)
} } else {

DispatchQueue.main.async {
completion(nil, nil)
}}});}

Step 4:- Setting

4.1) Launch the Settings app on your iOS device → Passwords & Accounts.

public record

app passwords

4.2) Now, tap on Website & App Passwords.

4.3) You need to go to Settings → Safari → AutoFill → Turn on the switch next to Names and Passwords.

Turn on the switch next to Names and Passwords

Now, tap on Website & App Passwords.

create a new project

Need Expert Guidance?

Talk to our experts and get recommendations tailored to your project.

About the Author

Nikhil Solanki

Mobile Lead at Manek Tech

Nikhil Solanki has 10+ years of experience in App Development and currently works as the Mobile Lead at ManekTech. He is an experienced Mobile lead with a demonstrated history of working in Mobile's information technology and services industry.

More articles on the topic

Mobile App Development Firebase Analytics In Mobile App

An app's user base using Firebase Analytics, a free and unlimited analytics solution. You'll be able to learn who your users are and how they interact with your app.

7 Min ReadFeb 27, 24

Nikhil Solanki

Nikhil Solanki

Mobile Lead at Manek Tech

DevOps Consider These Top 4 Data Visualization Tools

Data Visualization technologies provide us with a proliferation of insights into the data obtained. Google and Microsoft, for instance, gather and utilize Big Data to shape the future of their commercial operations.

4 Min ReadFeb 29, 24

Ruchir Pandya

Ruchir Pandya

Delivery Head of Web at Manek Tech