Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. let context : LAContext = LAContext()
  2. var error: NSError?
  3.  
  4. if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: &error) {
  5. context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication,
  6. localizedReason: messageString,
  7.  
  8.  
  9. reply: { (success: Bool, evalPolicyError: Error?) -> Void in
  10.  
  11. if success {
  12. //... perform login
  13. }
  14. }
  15. else {
  16.  
  17. switch evalPolicyError!._code {
  18.  
  19. case LAError.systemCancel.rawValue:
  20. print("Authentication was cancelled by the system")
  21.  
  22. case LAError.userCancel.rawValue:
  23. print("Authentication was cancelled by the user")
  24.  
  25. case LAError.userFallback.rawValue:
  26. print("User selected to enter custom password")
  27.  
  28. default:
  29. print("Authentication failed")
  30. OperationQueue.main.addOperation({ () -> Void in
  31. print("Error input")
  32. })
  33. }
  34. }
  35.  
  36. })
  37. }
  38. else {
  39. // If the security policy cannot be evaluated then show a short message depending on the error.
  40. switch error!.code{
  41.  
  42. case LAError.touchIDNotEnrolled.rawValue:
  43. print("TouchID is not enrolled")
  44.  
  45. case LAError.passcodeNotSet.rawValue:
  46. print("A passcode has not been set")
  47.  
  48. default:
  49. // The LAError.TouchIDNotAvailable case.
  50. print("TouchID not available")
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement