Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created October 3, 2018 08:53
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 fitomad/0007b710b65b6eb999182e88cb8b2f82 to your computer and use it in GitHub Desktop.
Save fitomad/0007b710b65b6eb999182e88cb8b2f82 to your computer and use it in GitHub Desktop.
self.authenticationContext = LAContext()
var errorPolicy: NSError?
if let authenticationContext = self.authenticationContext,
authenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &errorPolicy)
{
authenticationContext.localizedCancelTitle = NSLocalizedString("CONTEXT_CANCEL_TITLE", comment: "")
authenticationContext.localizedFallbackTitle = NSLocalizedString("CONTEXT_FALLBACK_TITLE", comment: "")
let authenticationReason = NSLocalizedString("CONTEXT_REASON", comment: "")
authenticationContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: authenticationReason ) { (success: Bool, error: Error?) -> Void in
if success
{
print(NSLocalizedString("AUTHENTICATION_SUCCESS_MESSAGE", comment: ""))
DispatchQueue.main.async
{
self.presentImage()
}
}
else
{
if let error = error
{
print(error.localizedDescription)
if let contextError = LAError.Code(rawValue: error._code)
{
print(contextError.localizedDescription)
}
}
else
{
print(NSLocalizedString("AUTHENTICATION_ERROR_MESSAGE", comment: ""))
}
}
}
}
else
{
let message = errorPolicy?.localizedDescription ?? NSLocalizedString("AUTHENTICATION_POLICY_ERROR_MESSAGE", comment: "")
print(message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment