Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created March 22, 2020 18:48
Show Gist options
  • Save vialyx/d0bf3d6e518db77b732a8a8df4900ad6 to your computer and use it in GitHub Desktop.
Save vialyx/d0bf3d6e518db77b732a8a8df4900ad6 to your computer and use it in GitHub Desktop.
import Foundation
import LocalAuthentication
class ViewModel: ObservableObject {
@Published
var loggedIn: Bool = false
@Published
var hasChanges: Bool = false
private var domainState: Data?
func auth() {
let context = LAContext()
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Biometric Auth") {
[weak self] (res, err) in
DispatchQueue.main.async {
self?.loggedIn = res
}
}
}
func check() {
let context = LAContext()
context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
checkDomainState(context.evaluatedPolicyDomainState)
}
private func checkDomainState(_ domainState: Data?) {
if let `domainState` = domainState {
if domainState != self.domainState {
hasChanges = true
} else {
hasChanges = false
}
}
self.domainState = domainState
hasChanges = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment