Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import LocalAuthentication
  2.  
  3. func afterUserAuthorized(perform handler: @escaping (Bool)->()) {
  4. let context = LAContext()
  5. var error:NSError?
  6.  
  7. /* .deviceOwnerAuthentication - using Touch ID or the device password
  8. .deviceOwnerAuthenticationWithBiometrics - use Touch ID only */
  9. guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else {
  10. fatalError("No TouchID or passcode set on this device")
  11. }
  12.  
  13. context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Please, pass authorisation to enter this area") { success, error in
  14. guard success else {
  15. print("Error: \(error)")
  16. /* where error can be one of: .authenticationFailed, .userCancel, .userFallback, .systemCancel,
  17. .passcodeNotSet, .touchIDNotAvailable, .touchIDNotEnrolled */
  18. handler(false)
  19. return
  20. }
  21.  
  22. print("Hooray! User passed!")
  23. handler(true)
  24. }
  25. }
Add Comment
Please, Sign In to add comment