Files

24 lines
644 B
Swift
Raw Permalink Normal View History

//
// BiometricAuthService.swift
// KeeVault
//
import LocalAuthentication
import Foundation
public final class BiometricAuthService {
public init() {}
public var isAvailable: Bool {
let ctx = LAContext()
var error: NSError?
return ctx.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
}
/// Returns true on success. On failure, throws an error with a localized message.
public func authenticate(reason: String) async throws {
let ctx = LAContext()
try await ctx.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason)
}
}