Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 如何使用TouchIDAuthenticationAllowableReuseEduation_Ios_Swift_Localauthentication - Fatal编程技术网

Ios 如何使用TouchIDAuthenticationAllowableReuseEduation

Ios 如何使用TouchIDAuthenticationAllowableReuseEduation,ios,swift,localauthentication,Ios,Swift,Localauthentication,当应用程序启动或将进入前台时,我通过LAContext对用户进行身份验证。如果设备被锁定,则会要求用户两次授权。为了避免这种行为,我将context.touchIDAuthenticationAllowableReuseEduration值设置为240,但它没有按预期工作。用户仍然必须对自己进行两次授权。 我做错了什么 每次都需要使用相同的LAContext对象来获得该行为 class AccessControl { // MARK: - Singleton public s

当应用程序启动或将进入前台时,我通过LAContext对用户进行身份验证。如果设备被锁定,则会要求用户两次授权。为了避免这种行为,我将context.touchIDAuthenticationAllowableReuseEduration值设置为240,但它没有按预期工作。用户仍然必须对自己进行两次授权。 我做错了什么



每次都需要使用相同的
LAContext
对象来获得该行为

class AccessControl {

    // MARK: - Singleton
    public static let shared = AccessControl()

    // Policy
    private var policy: LAPolicy = .deviceOwnerAuthentication

    // Reason
    private var reason: String = NSLocalizedString("auhenticationLocalizedFallbackTitle", comment: "")

    // Context
    lazy var context: LAContext = {
        let mainContext = LAContext()
        if #available(iOS 9.0, *) {
            // specify your interval
            mainContext.touchIDAuthenticationAllowableReuseDuration = 60
        }
        return mainContext
    }()


    // Evaluate
    func evaluateUserWithBiometricsOrPasscode(success: @escaping () -> Void, error: @escaping () -> Void) {

        guard context.canEvaluatePolicy(policy, error: nil) else {
            error()
            return
        }
        context.evaluatePolicy(policy, localizedReason: reason) { eStatus, eError in
            DispatchQueue.main.async {
                if eStatus {
                    success()
                } else {
                    error()
                }
            }
        }
    }
}
并按如下方式调用此函数:这也适用于FaceID身份验证

AccessControl.shared.evaluateUserWithBiometricsOrPasscode(success: {

}) {

}
AccessControl.shared.evaluateUserWithBiometricsOrPasscode(success: {

}) {

}