Skip to content

Instantly share code, notes, and snippets.

@sourleangchhean168
Last active January 31, 2020 17:20
Show Gist options
  • Select an option

  • Save sourleangchhean168/080294527a65f0faa131441949c90aff to your computer and use it in GitHub Desktop.

Select an option

Save sourleangchhean168/080294527a65f0faa131441949c90aff to your computer and use it in GitHub Desktop.

Revisions

  1. sourleangchhean168 revised this gist Jan 31, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions biometrictype.swift
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    //Noted: This code is written in Swift 5.1
    //By: Sour Leangchhean

    import LocalAuthentication

  2. sourleangchhean168 revised this gist Jan 31, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions biometrictype.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    //Noted: This code is written in Swift 5.1

    import LocalAuthentication

    //Mark: BiometricType for define type
  3. sourleangchhean168 created this gist Jan 31, 2020.
    35 changes: 35 additions & 0 deletions biometrictype.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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()
    }
    }