2026-09-19 15:52:16 +02:00
|
|
|
//
|
|
|
|
|
// BiometricAuthService.swift
|
2026-09-20 15:05:19 +02:00
|
|
|
// KeeVault
|
2026-09-19 15:52:16 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|