我在我的 iOS 应用程序中使用 Face id。当用户验证失败时默认为重试无效。我想在用户单击重试时添加回调。请参阅下面的代码。我搜索了很多,但没有找到关于人脸 ID 的信息。
func startFaceIDTest(){
attempted = true
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
[unowned self] (successfaceID, authenticationError) in
DispatchQueue.main.async {
if successfaceID {
self.success = true
//self.unlockSecretMessage()
} else {
self.success = false
// let ac = UIAlertController(title: "Authentication failed", message: "You could not be verified; please try again.", preferredStyle: .alert)
// ac.addAction(UIAlertAction(title: "OK", style: .default))
// self.present(ac, animated: true)
}
}
}
} else {
if let err = error {
if #available(iOS 11.0, *) {
self.success = false
switch err.code {
case LAError.Code.biometryNotEnrolled.rawValue:
notifyUser("Your device not enrolled for biometric",
err: err.localizedDescription)
case LAError.Code.passcodeNotSet.rawValue:
notifyUser("A passcode has not been set",
err: err.localizedDescription)
case LAError.Code.biometryNotAvailable.rawValue:
notifyUser("Biometric authentication not available",
err: err.localizedDescription)
default:
notifyUser("Unknown error",
err: err.localizedDescription)
}
} else {
// Fallback on earlier versions
}
}
}
}