24 lines
642 B
Swift
24 lines
642 B
Swift
//
|
|||
|
|
// BiometricAuthService.swift
|
||
|
|
// MyPass
|
||
|
|
//
|
||
|
|
|
||
|
|
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)
|
||
|
|
}
|
||
|
|
}
|