Last active
March 16, 2018 13:35
-
-
Save Marcocanc/2792644db83693fe5c8c21155cd97439 to your computer and use it in GitHub Desktop.
BiometryType for iOS 8+
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 | |
extension LAContext { | |
/// BiometryType that works on iOS versions older than iOS 11. | |
var compatBiometryType: BiometryType { | |
var authError: NSError? | |
guard canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError), authError == nil else { return .none } | |
// On iOS 11 we can get the biometry type directly. | |
if #available(iOS 11.0, *) { | |
switch biometryType { | |
case .faceID: return .faceID | |
case .touchID: return .touchID | |
case .none: return .none | |
} | |
} | |
// On older versions it must be touchID. | |
return .touchID | |
} | |
} | |
/// The type of biometric authentication supported by the device. | |
enum BiometryType { | |
/// The device supports Touch ID. | |
case touchID | |
/// The device supports Face ID. | |
case faceID | |
/// No biometry type is supported. | |
case none | |
/// The name of the biometrics technology (e.g. Face ID) | |
var localizedDescription: String { | |
switch self { | |
case .faceID: | |
return "Face ID" | |
case .touchID: | |
return "Touch ID" | |
case .none: | |
return "" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment