Last active
December 20, 2016 15:01
-
-
Save 4np/c1e3f45206f96e5552ecbf0cc59ebffd to your computer and use it in GitHub Desktop.
Using touch ID
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
import LocalAuthentication | |
... | |
private func authenticateUser() { | |
let context = LAContext() | |
var error: NSError? | |
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { | |
let reason = "Identify yourself!" | |
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { | |
[unowned self] success, authenticationError in | |
DispatchQueue.main.async { | |
if success { | |
debugPrint("authorized!") | |
} else { | |
let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert) | |
ac.addAction(UIAlertAction(title: "OK", style: .default)) | |
self.present(ac, animated: true) | |
} | |
} | |
} | |
} else { | |
let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch ID.", preferredStyle: .alert) | |
ac.addAction(UIAlertAction(title: "OK", style: .default)) | |
present(ac, animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment