iOS - 本地身份验证更改失败消息 [英] iOS - Local authentication change fail message

查看:37
本文介绍了iOS - 本地身份验证更改失败消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一项 LA 服务,它几乎像往常一样使用 TouchID.问题是我想更改提示 touchId 身份验证时显示的警报上写的内容.首先它显示我在原因字符串中声明的内容,如果身份验证失败,它只会将标题更改为重复",但正文保持不变.

There's a LA service in my app that uses TouchID pretty much as usual. The problem is that I want to change what is written on the alert that shows up when touchId authentication is prompted. First it shows what I declare in reason string, than if auth fails, it only changes title to 'Repeat', but body stays the same.

当身份验证失败时,是否有机会为不同的消息更改警报的正文?我尝试更改原因字符串但没有效果.

Is there any chance to change the alert's body for a different message when auth fails? I tried changing reason string but no effect.

这个项目是使用 Xamarin 创建的,但是 Objective-C/Swift 代码也是可以接受的.提前致谢!

This project is created using Xamarin, but Objective-C/Swift code is also acceptable. Thanks in advance!

UPD:这是我的代码:

UPD: here's my code:

if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError))
            {
                var myReason = new NSString("Use your finger to authenticate");

                replyHandler = new LAContextReplyHandler((success, error) =>
                {
                    InvokeOnMainThread(() =>
                    {
                        if (success)
                        {
                            Login();
                        }
                        else
                        {
                            myReason = new NSString("Nope try again");

                            switch ((long)error.Code)
                            {
                                case (long)LAStatus.TouchIDLockout: // 5 times wrong, TouchID is locked system-wide
                                    {
                                        var alert = new UIAlertView("Sorry", "Exceeded and blocked message", null, "OK");
                                        alert.Show();
                                        touchIdButton.Hidden = true;
                                    }
                                    break;
                                case (long)LAStatus.AuthenticationFailed: // 3 times wrong
                                    {
                                        var alert = new UIAlertView("Sorry", "Exceeded message", null, "OK");
                                        alert.Show();
                                        touchIdButton.Hidden = true;
                                    }
                                    break;
                                case (long)LAStatus.UserFallback: //Enter Passcode
                                    //no UserFallback for now
                                    break;
                            }

                        }
                    });
                });
                context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);

推荐答案

没有.没有用于在身份验证过程之间更改原因的 API.

No. There is no API for changing the Reason in between the auth process.

参见 https://developer.apple.com/documentation/localauthentication/lacontext/1514176-evaluatepolicy

localizedReason

应用提供的请求身份验证的原因,显示在呈现给用户的身份验证对话框中.

The app-provided reason for requesting authentication, which displays in the authentication dialog presented to the user.

这意味着:您正在尝试的内容并非 Apple 有意为之.请求身份验证的原因保持不变,独立于失败的尝试计数.换句话说:在第一次尝试失败后,您提出请求的原因并没有改变.

This means: What you are trying is not intended by Apple. The reason for requesting the auth stays the same independent from the failed try count. In other words: Your reason for requesting hasn't change after the first failed attempt.

广告部分

如果您对指纹认证的跨平台解决方案感兴趣,请查看我的插件:) https://github.com/smstuebe/xamarin-fingerprint

If you are interested in a cross platform solution for fingerprint auth, have a look at my plugin :) https://github.com/smstuebe/xamarin-fingerprint

这篇关于iOS - 本地身份验证更改失败消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆