tokenary/Tokenary iOS/Library/LocalAuthentication.swift
2021-12-10 18:58:03 +03:00

25 lines
816 B
Swift

// Copyright © 2021 Tokenary. All rights reserved.
import LocalAuthentication
struct LocalAuthentication {
static func attempt(reason: String, completion: @escaping ((Bool) -> Void)) {
let context = LAContext()
var error: NSError?
let policy = LAPolicy.deviceOwnerAuthenticationWithBiometrics
let canDoLocalAuthentication = context.canEvaluatePolicy(policy, error: &error)
if canDoLocalAuthentication {
context.localizedCancelTitle = Strings.cancel
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, _ in
DispatchQueue.main.async {
completion(success)
}
}
} else {
completion(false)
}
}
}