Require Face ID to open the app and to send

This commit is contained in:
2026-09-27 23:35:26 +08:00
parent b989b0f791
commit 78e1cefad4
8 changed files with 172 additions and 7 deletions
+25
View File
@@ -0,0 +1,25 @@
import Foundation
import LocalAuthentication
/// Face ID / Touch ID gating for the app lock and for sensitive actions.
enum Biometrics {
static var isAvailable: Bool {
LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
}
static var label: String {
let context = LAContext()
_ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
return context.biometryType == .faceID ? "Face ID" : "Touch ID"
}
/// Biometrics with the system passcode fallback (the alert offers "Use
/// Passcode" after a failed face scan).
static func authenticate(reason: String) async -> Bool {
guard isAvailable else { return false }
let context = LAContext()
context.localizedCancelTitle = "Cancel"
return (try? await context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: reason)) ?? false
}
}