【问题标题】:How to handle error cases in Biometric authentication for iOS in Xamarin?如何在 Xamarin 中处理 iOS 生物识别身份验证中的错误情况?
【发布时间】:2018-06-04 05:02:17
【问题描述】:
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条件下的错误情况。

【问题讨论】:

    标签: ios xamarin xamarin.ios fingerprint localauthentication


    【解决方案1】:

    您可以从返回的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:

    【讨论】:

    • 好的,我去看看。
    猜你喜欢
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 2020-06-26
    • 2021-07-11
    • 1970-01-01
    • 2017-09-23
    相关资源
    最近更新 更多