Thursday, August 11, 2022
HomeiOS Developmentios - SwiftUI Biometric authentication as an optionally available function in software...

ios – SwiftUI Biometric authentication as an optionally available function in software to dam the UI behind


I’m new to SwiftUI and I want to use the Biometric authentication(Face ID, Contact ID) to lock the UI behind. I may try this as a compulsory examine(utilizing a flag isUnlocked). However I must set it as a choice for person.Consumer ought to have the ability to On/OFF the function from a special tab say Settings.

I used beneath code for authenticating person

    @State non-public var isUnlocked = false
var physique: some View {
    TabView{
        if isUnlocked{
            HomeView()
                .tabItem {
                    Label("Dwelling", systemImage: "home")
                }
            CategoryView()
                .tabItem {
                    Label("Class", systemImage: "checklist.bullet.rectangle.portrait")
                }
            SettingsView()
                .tabItem {
                    Label("Settings", systemImage: "gearshape.2")
                }
        }else{
            Button("Unlock"){
                authenticate()
            }
        }
    }
}

func authenticate(){
    let context = LAContext()
    var error : NSError?
    let purpose = "Please unlock the gadget to see info"
    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error){
        context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: purpose) { success, error in
            if success{
                isUnlocked = true
            }
        }
    }
}

How can I obtain this

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments