Last active
May 25, 2018 13:50
-
-
Save vishw33/c69375c779c5605490c15f8d611b8bf9 to your computer and use it in GitHub Desktop.
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
| static func isValidUer(reasonString:String , Success: @escaping AuthSuccessBlock = { _ in }) | |
| { | |
| var policy: LAPolicy? | |
| let context = LAContext() | |
| if #available(iOS 9.0, *) | |
| { | |
| /* | |
| deviceOwnerAuthenticationWithBiometrics can be used when you want to authenticate user solely based on | |
| bioMetric without reverting to PassCode if bioMetric fail | |
| simple :- biometricfail == policy Fail | |
| deviceOwnerAuthentication can be used when you want to authenticate based on bioMetric but also have | |
| a option to enter passcode if fail | |
| simple :- biometricfail = switch to passcode | |
| passcode_Also_fail = policy fail | |
| */ | |
| policy = .deviceOwnerAuthentication | |
| } | |
| context.evaluatePolicy(policy!, localizedReason: reasonString, reply: { (successAuth, error) in | |
| DispatchQueue.main.async { | |
| if successAuth | |
| { | |
| Success(true , nil) | |
| } | |
| else | |
| { | |
| guard let error = error else { | |
| Success(false , "UnknownError") | |
| return | |
| } | |
| switch (error) | |
| { | |
| case LAError.authenticationFailed: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.userCancel: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.userFallback: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.systemCancel: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.passcodeNotSet: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.touchIDNotAvailable: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.touchIDNotEnrolled: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.touchIDLockout: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.appCancel: | |
| Success(false , error.localizedDescription) | |
| break | |
| case LAError.invalidContext: | |
| Success(false , error.localizedDescription) | |
| break | |
| default: | |
| break | |
| } | |
| return | |
| } | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment