Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在每次faceid/touchid身份验证失败时获取回调_Ios_Swift_Iphone_Touch Id_Face Id - Fatal编程技术网

Ios 如何在每次faceid/touchid身份验证失败时获取回调

Ios 如何在每次faceid/touchid身份验证失败时获取回调,ios,swift,iphone,touch-id,face-id,Ios,Swift,Iphone,Touch Id,Face Id,我们有一个要求,如果脸ID或触摸ID连续5次出现故障,我们必须阻止用户24小时 在Face ID中,我再次使用fallback调用身份验证管理器,在总共尝试6次(每次调用2次)后,我在fallback方法本身中阻止用户 在Touch ID中,第三次失败时,我得到一个回拨,以验证失败。我再次调用authentication manager,在第5次尝试时,我收到一个回拨到Lockout的电话,我可以在其中阻止用户 在Face ID和Touch ID中是否有任何共同的方法,在每次单个故障后我都可以得

我们有一个要求,如果脸ID或触摸ID连续5次出现故障,我们必须阻止用户24小时

在Face ID中,我再次使用fallback调用身份验证管理器,在总共尝试6次(每次调用2次)后,我在fallback方法本身中阻止用户

在Touch ID中,第三次失败时,我得到一个回拨,以验证失败。我再次调用authentication manager,在第5次尝试时,我收到一个回拨到Lockout的电话,我可以在其中阻止用户

在Face ID和Touch ID中是否有任何共同的方法,在每次单个故障后我都可以得到回调,以便在第五次故障时阻止用户

//MARK:- Check if user has valid biometry, if yes, validate, else, show error
fileprivate func biometricAuthentication(completion: @escaping ((Bool) -> ())){
    //        addBlurredBackground()
    //Check if device have Biometric sensor
    if biometryRetryCount == 2 {
        authenticationContext.localizedFallbackTitle = "Ok"
    } else {
        authenticationContext.localizedFallbackTitle = "Retry"
    }

    let isValidSensor : Bool = authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)

    if isValidSensor {
        //Device have BiometricSensor
        authenticationContext.evaluatePolicy(
            .deviceOwnerAuthenticationWithBiometrics,
            localizedReason:  biometryRetryCount == 2 ? "You have been blocked from using the application for next 24 hours. Please come back later" : "Touch / Face ID authentication",
            reply: { [unowned self] (success, error) -> Void in

                if(success) {
                    // Touch or Face ID recognized
                    //                        self.removeBlurredBackground()
                    completion(true)
                } else {
                    //If not recognized then
                    if let error = error {
                        let msgAndAction = self.errorMessage(errorCode: error._code)
                        if msgAndAction.0 != "" {
                            UIApplication.topViewController()?.showAlert(withTitle: "Error", andMessage: msgAndAction.0, andActions: msgAndAction.1)
                        }
                    }
                    completion(false)
                }
        })
    } else {
        let msgAndAction = self.errorMessage(errorCode: (error?._code)!)
        if msgAndAction.0 != ""{
            UIApplication.topViewController()?.showAlert(withTitle: "Error", andMessage: msgAndAction.0, andActions: msgAndAction.1)
        }
    }

}
错误方法:

//MARK: TouchID error
fileprivate func errorMessage(errorCode:Int) -> (strMessage: String, action: [UIAlertAction]){

    var strMessage = ""
    let cancelAction = UIAlertAction.init(title:  Const.Localize.Common().kCancel, style: .cancel) { (cancelAction) in
    }
    var actions: [UIAlertAction] = [cancelAction]

    switch errorCode {

    case LAError.Code.authenticationFailed.rawValue:
        biometricAuthentication { (success) in
            //
        }
    case LAError.Code.userCancel.rawValue:
        if biometryRetryCount == 2 {
            blockUserFor24Hours()
        } else {
            showAlertOnCancelTapAction()
        }
    case LAError.Code.passcodeNotSet.rawValue:
        strMessage = "Please goto the Settings & Turn On Passcode"
    case LAError.Code.userFallback.rawValue:
        biometryRetryCount -= 2
        if biometryRetryCount == 0 {
            blockUserFor24Hours()
        } else {
            biometricAuthentication { (success) in
                //
            }
        }
    default:
        strMessage = evaluatePolicyFailErrorMessageForLA(errorCode: errorCode).strMessage
        actions = evaluatePolicyFailErrorMessageForLA(errorCode: errorCode).action
    }

    return (strMessage, actions)
}


func evaluatePolicyFailErrorMessageForLA(errorCode: Int) -> (strMessage: String, action: [UIAlertAction]){
    let cancelAction = UIAlertAction.init(title:  Const.Localize.Common().kCancel, style: .cancel) { (cancelAction) in
    }
    var actions: [UIAlertAction] = [cancelAction]

    var message = ""
    if #available(iOS 11.0, macOS 10.13, *) {
        switch errorCode {
        case LAError.biometryNotAvailable.rawValue:
            message = "Authentication could not start because the device does not support biometric authentication."

        case LAError.biometryLockout.rawValue:
            showPasscodeScreen()

        case LAError.biometryNotEnrolled.rawValue:
            message = "You do not have a registered biometric authentication. Kindly go to the settings and setup one"
            let settingsAction = UIAlertAction.init(title:  Const.Localize.Common().kSetting, style: .default) { (settingsAction) in
                UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
            }
            actions.append(settingsAction)

        default:
            message = "Did not find error code on LAError object"
        }
    } else {
        switch errorCode {
        case LAError.touchIDLockout.rawValue:
            showPasscodeScreen()
        case LAError.touchIDNotAvailable.rawValue:
            message = "TouchID is not available on the device"
        case LAError.touchIDNotEnrolled.rawValue:
            message = "You do not have a registered biometric authentication. Kindly go to the settings and setup one"
            let settingsAction = UIAlertAction.init(title:  Const.Localize.Common().kSetting, style: .default) { (settingsAction) in
                UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
            }
            actions.append(settingsAction)

        default:
            message = "Did not find error code on LAError object"
        }
    }

    return (message, actions)
}

在一台设备上,您将拥有FaceID或TouchID,那么您所说的公共回调是什么意思呢?我想避免为两种不同的场景编写逻辑。看现在,我阻塞了6个面部ID故障和5个触摸ID故障。我想探讨出现常见5种故障的可能性。在一台设备上,您将使用FaceID或TouchID,那么您所说的常见回调是什么意思?我想避免为两种不同的情况编写逻辑。看现在,我阻塞了6个面部ID故障和5个触摸ID故障。我想探讨5种常见故障的可能性。