UnlockManager.swift 593 B

12345678910111213141516171819202122232425
  1. import Combine
  2. import LocalAuthentication
  3. protocol UnlockManager {
  4. func unlock() async throws -> Bool
  5. }
  6. struct UnlockError: Error {
  7. let error: Error?
  8. }
  9. final class BaseUnlockManager: UnlockManager {
  10. @MainActor func unlock() async throws -> Bool {
  11. let context = LAContext()
  12. let reason = "We need to make sure you are the owner of the device."
  13. do {
  14. _ = try await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)
  15. return true
  16. } catch {
  17. throw UnlockError(error: error)
  18. }
  19. }
  20. }