save username and password in key chain and use that as autofill
Asked Answered
S

1

2

I am trying to achieve like, when user already have their account. When they try to enter username and password i need to show the bottom popup to save your password like website ask to save our credentials when we logging in safari. So if user tap on save let it save in key chain.

And next time when user tap of user name or password an autofill credentials will be given to user and select their credentials.

my code :

   let server = "www.workBro.com"
    let userName = userNameTF.text
    let passWrd = passwordTF.text

    let password = passWrd?.data(using: String.Encoding.utf8)
    var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
                                kSecAttrAccount as String: userName,
                                kSecAttrServer as String: self.server,
                                kSecValueData as String: password]
    let status = SecItemAdd(query as CFDictionary, nil)
    if status == errSecSuccess {
        print("success")
    } else {
        print("fail")
    }

My credentials got saved i got success. But it din ask for shall i save your password promt alert like what we get when we use mobile safari login with other sites.

Am i missing anything ?

Subsumption answered 23/4, 2020 at 14:43 Comment(1)
did you figure it out?Insatiate
I
3

the complete guide is in the article iOS 12 Password Tools: Improving User Security and Experience:

1-get your App’s Identifiers from Apple developer Portal

2-on your app and Apple developer portal, you have to enable Autofill compatibility

3-Add apple-app-site-association in the Web App "Web Server" Supporting Associated Domains in Your App

4- on your App's Capabilities enable Associated Domains

5-text field content types must be Username and Password in the attribute inspector

Insatiate answered 23/4, 2020 at 16:49 Comment(6)
i dont want to access for the web site. I just want like when user enter his user name and password i need to show save password... And if user tap on save password..on next login i need to get credentials from autofillSubsumption
you can't achieve the autofill through programming alone. you need to configure your app and Apple developer portal to save it in iCloud keychainInsatiate
the most important puzzle piece is apple-app-site-associationInsatiate
yeah, so i understand 1, 2, 4, 5..But 3. Add apple-app-site-association in the Web App "Web Server" Supporting Associated Domains in Your App. I have to create some file and i need to add it in my web server ?.Subsumption
can i skip 3, because my application doesn't have any web app. I have only mobile app. Then why i need to do step 3 ?Subsumption
do you have a Website hosting server AKA"Web App"? no, you can't skip 3 because the app OS "iOS" will check apple-app-site-association file in your website root. just sign up with heroku.com for a small webserver and use the steps in the article to add your apple-app-site-associationInsatiate

© 2022 - 2024 — McMap. All rights reserved.