Last active
January 31, 2020 17:20
-
-
Save sourleangchhean168/080294527a65f0faa131441949c90aff to your computer and use it in GitHub Desktop.
Check device support biometric type in iOS
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
//Noted: This code is written in Swift 5.1 | |
//By: Sour Leangchhean | |
import LocalAuthentication | |
//Mark: BiometricType for define type | |
enum BiometricType{ | |
case touchID | |
case faceID | |
case none | |
} | |
func getBiometricThisDevice() -> BiometricType{ | |
let authContext = LAContext() | |
let _ = authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) | |
switch (authContext.biometryType){ | |
case .faceID: | |
return .faceID | |
case .touchID: | |
return .touchID | |
default: | |
return .none | |
} | |
} | |
// Mark: How to use it in SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Text("This device support \(getBiometricThisDevice() == .faceID ? "FaceID" : "Touch ID")") | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment