1

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?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • 1
    The only way a user can authenticate after tapping cancel is for your app to call `context.evaluatePolicy` again. – rmaddy Oct 05 '18 at 15:09

2 Answers2

1

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
-2

Try with code Obj-C, I think that Swift is the same logic

self.context = [[LAContext alloc] init];
[self.context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
        localizedReason:strMessage
                  reply:^(BOOL success, NSError *error) {

                      dispatch_async(dispatch_get_main_queue(), ^{

                          if (error) {
                              if (error.code == LAErrorUserFallback) {
                                  //Do some thing
                              }else if (error.code == LAErrorAuthenticationFailed) {
                                  //User authen failed
                              }else if (error.code == LAErrorUserCancel) {
                                  //User cancel
                              }else{
                                  //Something wrong...
                              }
                              return;
                          }

                          if (success) {
                             //Success
                          } else {
                            //Failed
                              return;
                          }
                      });

                  }];
Chuong Tran
  • 3,131
  • 17
  • 25