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);
};

我想根据错误类型处理 else 条件下的错误情况。

4

1 回答 1

3

您可以从NSError返回的失败代码中获取并根据LAStatus代码进行处理:

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

LAStatus(去掉了弃用):

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
}

对于各种代码的描述,您可以使用 LAError.Code:

于 2018-06-04T05:39:13.120 回答