0
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)){
    var replyHandler = new LAContextReplyHandler((success, error) => {
        this.InvokeOnMainThread(()=> {
            if(success)
            {
                Console.WriteLine("You logged in!");
                PerformSegue("AuthenticationSegue", this);
            }
            else
            {
                // Show fallback mechanism here
            }
        });
    });
    context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);
};

I want to handle the error cases in the else condition based on the type of error.

subin272
  • 733
  • 6
  • 24

1 Answers1

3

You can obtain the failure code from the NSError returned and process it against the LAStatus codes:

switch (error.Code)
{
    case (long)LAStatus.AuthenticationFailed:
        ~~~
        break;
    case (long)LAStatus.UserCancel:
        ~~~
        break;
    ~~~
    default:
        break;
}

LAStatus (with the deprecations stripped out):

public enum LAStatus : long
{
    Success,
    AuthenticationFailed = -1L,
    UserCancel = -2L,
    UserFallback = -3L,
    SystemCancel = -4L,
    PasscodeNotSet = -5L,
    AppCancel = -9L,
    InvalidContext = -10L,
    BiometryNotAvailable = -6L,
    BiometryNotEnrolled = -7L,
    BiometryLockout = -8L,
    NotInteractive = -1004L
}

For descriptions of the various codes, you can use LAError.Code:

SushiHangover
  • 73,120
  • 10
  • 106
  • 165