Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import LocalAuthentication
- func afterUserAuthorized(perform handler: @escaping (Bool)->()) {
- let context = LAContext()
- var error:NSError?
- /* .deviceOwnerAuthentication - using Touch ID or the device password
- .deviceOwnerAuthenticationWithBiometrics - use Touch ID only */
- guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else {
- fatalError("No TouchID or passcode set on this device")
- }
- context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Please, pass authorisation to enter this area") { success, error in
- guard success else {
- print("Error: \(error)")
- /* where error can be one of: .authenticationFailed, .userCancel, .userFallback, .systemCancel,
- .passcodeNotSet, .touchIDNotAvailable, .touchIDNotEnrolled */
- handler(false)
- return
- }
- print("Hooray! User passed!")
- handler(true)
- }
- }
Add Comment
Please, Sign In to add comment