Last active
December 1, 2021 17:54
-
-
Save knowsudhanshu/015fdc17eea5937204a948dff31289d3 to your computer and use it in GitHub Desktop.
TouchID and FaceID integration
This file contains hidden or 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
struct BiometricIDHandler { | |
static func authenticateWithBiometrics() { | |
let laContext = LAContext() | |
var error: NSError? | |
if laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, | |
error: &error) { | |
let reason = "Identify yourself!" | |
laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in | |
if let authError = authenticationError { | |
let error = authError as NSError | |
switch error.code { | |
case LAError.systemCancel.rawValue: | |
// NOTE: This can happen due to any situation e.g. phone call or user drags notification drawer | |
break | |
case LAError.userCancel.rawValue: | |
// NOTE: User tapped cancel button | |
break | |
default: | |
// NOTE: There are several other `enum` values | |
break | |
} | |
} | |
else { | |
DispatchQueue.main.async { | |
if success { | |
} | |
else { | |
} | |
} | |
} | |
} | |
} | |
else { | |
print(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment