ios - 如何在 Xamarin 中处理 iOS 生物识别身份验证中的错误情况?

标签 ios xamarin xamarin.ios fingerprint localauthentication

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 条件下的错误情况。

最佳答案

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

关于ios - 如何在 Xamarin 中处理 iOS 生物识别身份验证中的错误情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50673665/

相关文章:

ios - .car 在 iOS 中代表什么?编译 Assets (______)..?

iphone - UITableView的后台view怎么写(主要是Instructions)

c# - 如何设置 Xamarin MonoMac 项目,使其构建输出 .app 包而不是 .exe?

c# - (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,3) : error MSB6006: "java.exe" exited with code 1

iOS UITextInput 控件 : Receiving forward-delete key from hardware keyboard

c# - 依赖注入(inject)的 Xamarin iOS Controller 自定义继承问题

ios - AVAudioPlayer 不播放文件夹内的歌曲?

ios - 在自己的窗口中显示 UIAlertController 时出现 NSException

c# - 如何将 SwitchCell 文本颜色绑定(bind)到 Xamarin.Forms 中的 View 模型

xamarin.ios - 在 MvvmCross monodroid Activity 中插入 Monogame View