Instantly share code, notes, and snippets.

Embed
What would you like to do?
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