Skip to content

Instantly share code, notes, and snippets.

@knowsudhanshu
Last active December 1, 2021 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knowsudhanshu/015fdc17eea5937204a948dff31289d3 to your computer and use it in GitHub Desktop.
Save knowsudhanshu/015fdc17eea5937204a948dff31289d3 to your computer and use it in GitHub Desktop.
TouchID and FaceID integration
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