I am authenticating a user via LAContext when an app is launching or when will enter foreground. If a device was locked then the user will be asked twice to authorize himself. To avoid that behavior, I set context.touchIDAuthenticationAllowableReuseDuration value to 240 but It doesn't work as expected. The user still has to authorize himself twice. What I am doing wrong?
import LocalAuthentication
class AccessControl {
internal var context = LAContext()
private var policy: LAPolicy = .deviceOwnerAuthentication
private var reason: String = NSLocalizedString("auhenticationLocalizedFallbackTitle", comment: "")
init() {
context.touchIDAuthenticationAllowableReuseDuration = 240
}
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()
}
}
}
}
}