问题
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