答案 0 :(得分:2)
您无法获取用户密码,但您可以对用户进行身份验证并让他们使用他们的TouchID / FaceID
为此,您将要使用LocalAuthentication框架。
以下是一个例子:
let myContext = LAContext()
let myLocalizedReasonString = <#String explaining why app needs authentication#>
var authError: NSError?
if #available(iOS 8.0, macOS 10.12.1, *) {
if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in
if success {
// User authenticated successfully, take appropriate action
} else {
// User did not authenticate successfully, look at error and take appropriate action
}
}
} else {
// Could not evaluate policy; look at authError and present an appropriate message to user
}
} else {
// Fallback on earlier versions
}
信用:Apple