将Face ID生物特征认证限制为3

时间:2020-06-10 10:03:41

标签: swift authentication biometrics face-id

我的应用程序可以使用生物识别身份验证,而ios应用程序仅尝试进行2次面部识别生物识别,问题是,在添加输入密码选项之前,我需要使其进行3次尝试,我该怎么办那?

这是我用于访问生物识别身份验证的代码

func loginWithBiometrics() {
        let context = LAContext()
        var error: NSError?

        if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
            let reason = "Identify yourself!"

            context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { [weak self] success, authenticationError in
                DispatchQueue.main.async {
                    if success {
                        print("success")
                    } else {
                        print("Failed biometric!")
                    }
                }
            }
        } else {
            print("Biometric not available!")
        }
}

它只会尝试两次输入人脸ID,然后在两次出现人脸ID错误后建议您输入密码。

我的期望是让用户尝试3次而不是2次面部ID。

1 个答案:

答案 0 :(得分:4)

根据Apple的说法,Touch ID会尝试进行三次验证,而Face ID只会尝试进行两次验证。我只能假设这是因为在某些国家(例如,温暖的国家/地区,汗水妨碍了传感器验证指纹的能力)下,触摸ID往往会经常失败。

如果Touch ID或Face ID不可用或未注册,则策略评估失败。在尝试三次失败的Touch ID之后,评估也将失败。在两次失败的Face ID尝试失败后,系统提供了一个后备选项,但停止尝试使用Face ID进行身份验证。

资源:https://developer.apple.com/documentation/localauthentication/lapolicy/deviceownerauthenticationwithbiometrics

相关问题