Skip to content

Instantly share code, notes, and snippets.

@sourleangchhean168
Last active January 31, 2020 17:20
Show Gist options
  • Save sourleangchhean168/080294527a65f0faa131441949c90aff to your computer and use it in GitHub Desktop.
Save sourleangchhean168/080294527a65f0faa131441949c90aff to your computer and use it in GitHub Desktop.
Check device support biometric type in iOS
//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