iosswiftlocalauthentication

How can I observe when user authenticates the app with biometrics?


Simply in code I use it like this:

let context = LAContext()
if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "jjj") { success, error in
        print(error)
        print(success)
    }
}

Then user can see:

enter image description here

Everything is fine until user tap Cancel. Then I display label:

"Please use biometrics to authenticate". NOW I need to get a callback after user was authenticated at any time after first try was cancelled. How can I detect this?


Solution

  • You don’t need a “callback” for this. If the user refuses authentication in response to the dialog, the only way authentication can happen is in Settings, i.e. outside your app. So just check for authentication every time your app comes to the foreground.