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

    About Author

    Manektech Team

    Nikhil Solanki

    Mobile Lead

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

    Subscribe to Our Newsletter!

    Join us to stay updated with our latest blog updates, marketing tips, service tips, trends, news and announcements!

    OUR OFFICES


    ManekTech's Global Presence

    USA

    4100 NW Loop 410, Suite 200, San Antonio, Texas, USA 78229

    UK

    7 Artisan Place Harrow, HA3 5DS

    India

    4th Floor, Timber Point, Prahaladnagar Road, Ahmedabad, Gujarat - 380015

    Germany

    Franz-Joseph-Strasse, 11,Munich, 80801, Germany

    South Africa

    The Business Centre No 1. Bridgeway Road, Bridgeway Precint, Century City, Cape Town, South Africa, 7446

    PREV
    NEXT