Add an async authentication extension to LAContext

This commit is contained in:
Daniel Saidi 2022-04-29 10:37:11 +02:00
parent b7bbe6acb3
commit 8de53563f7
4 changed files with 41 additions and 2 deletions

View File

@ -3,7 +3,7 @@
// Demo
//
// Created by Daniel Saidi on 2020-11-30.
// Copyright © 2020 Daniel Saidi. All rights reserved.
// Copyright © 2020-2022 Daniel Saidi. All rights reserved.
//
import SwiftKit

View File

@ -1,6 +1,14 @@
# Release notes
## 1.2
### ✨ New features
* `LAContext+Async` adds an async policy evaluation function.
## 1.1
### ✨ New features
@ -16,6 +24,7 @@
* `String+UrlEncode` now handles + as well.
## 1.0
I think it's finally time to push the major release button.
@ -42,6 +51,7 @@ This version also introduces a new `StoreKit` namespace with handy utils for man
* `StandardStoreService` is a new class that implements the `StoreService` protocol.
## 0.7.0
This version requires Xcode 13 and later, since it refers to the latest api:s.

View File

@ -3,7 +3,7 @@
// SwiftKit
//
// Created by Daniel Saidi on 2016-01-18.
// Copyright © 2020 Daniel Saidi. All rights reserved.
// Copyright © 2016 Daniel Saidi. All rights reserved.
//
import Foundation

View File

@ -0,0 +1,29 @@
//
// LAContext+Async.swift
// SwiftKit
//
// Created by Daniel Saidi on 2022-04-29.
// Copyright © 2016-2022 Daniel Saidi. All rights reserved.
//
import LocalAuthentication
@available(iOS 15.0, macOS 12.0, *)
extension LAContext {
/**
Evaluate a certain policy.
- Parameters:
- policy: The policy to evaluate.
- localizedReason: The localized reason to show to the user.
*/
func evaluatePolicy(_ policy: LAPolicy, localizedReason reason: String) async throws -> Bool {
return try await withCheckedThrowingContinuation { cont in
LAContext().evaluatePolicy(policy, localizedReason: reason) { result, error in
if let error = error { return cont.resume(throwing: error) }
cont.resume(returning: result)
}
}
}
}