save username and password in key chain and use that as autofill

爷,独闯天下 提交于 2020-05-17 06:24:30

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/61389979/save-username-and-password-in-key-chain-and-use-that-as-autofill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!