Created
March 22, 2020 18:48
-
-
Save vialyx/d0bf3d6e518db77b732a8a8df4900ad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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