Created
November 21, 2018 12:55
-
-
Save ioskevinshah/be6b4f31cb46b1dba03d73ff99cea6cf to your computer and use it in GitHub Desktop.
This file contains 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 | |
/// AuthenticationBlockState | |
enum AuthenticationBlockState { | |
case success | |
case failed | |
case canceledByUser | |
case fallback | |
case canceledBySystem | |
case passcodeNotSet | |
case biometryNotAvailable | |
case biometryNotEnrolled | |
case biometryLockedOut | |
case other | |
static func initWith(_ error: LAError?) -> AuthenticationBlockState { | |
if error == nil { | |
return .success | |
} else { | |
switch Int32(error!.errorCode) { | |
case kLAErrorAuthenticationFailed: | |
return .failed | |
case kLAErrorUserCancel: | |
return .canceledByUser | |
case kLAErrorUserFallback: | |
return .fallback | |
case kLAErrorSystemCancel: | |
return .canceledBySystem | |
case kLAErrorPasscodeNotSet: | |
return .passcodeNotSet | |
case kLAErrorBiometryNotAvailable: | |
return .biometryNotAvailable | |
case kLAErrorBiometryNotEnrolled: | |
return .biometryNotEnrolled | |
case kLAErrorBiometryLockout: | |
return .biometryLockedOut | |
default: | |
return other | |
} | |
} | |
} | |
func message() -> String { | |
switch self { | |
case .canceledByUser, .fallback, .canceledBySystem: | |
return "" | |
case .passcodeNotSet: | |
return kSetPasscode | |
case .biometryNotAvailable: | |
return kBiometryNotAvailableReason | |
case .biometryNotEnrolled: | |
return LocalAuthentication.isFaceIdAvailable ? kNoFaceIdentityEnrolled : kNoFingerprintEnrolled | |
case .biometryLockedOut: | |
return LocalAuthentication.isFaceIdAvailable ? kFaceIdPasscodeAuthenticationReason : kTouchIdPasscodeAuthenticationReason | |
default: | |
return LocalAuthentication.isFaceIdAvailable ? kDefaultFaceIDAuthenticationFailedReason : kDefaultTouchIDAuthenticationFailedReason | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment