首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LocalAuthentication框架-如何让“输入密码”在第一次调用时显示

LocalAuthentication框架-如何让“输入密码”在第一次调用时显示
EN

Stack Overflow用户
提问于 2016-04-07 05:42:56
回答 2查看 1.6K关注 0票数 5

我正在使用iOS的LocalAuthentication框架,并遵循了web上的一般教程来为我的应用程序实现TouchID身份验证。

当应用程序调用context.evaluatePolicy(policy,error:&error)时,我想向用户显示一个“输入密码”选项,而不是让用户选择“取消”关闭对话框并输入密码。

这是AppStore应用程序的默认行为,但我无法让我的应用程序以相同的方式执行。请看下面的AppStore截图:

我使用的代码与各种教程一致。请参阅下面的代码。

我的应用程序将启动,屏幕如下:

我已经到处搜索,在SO和其他网站上,但还没有能够启动我的应用程序与“显示密码”。当我使用未注册的手指验证LA时,对话框更改为"Try Try“,并有"Show Password”按钮。

代码语言:javascript
复制
        let context = LAContext()
        var error : NSError?

        // Test if TouchID policy is available on the device and a fingerprint has been enrolled.
        var policy : LAPolicy!
        if #available(iOS 9.0, *) {
            policy = (context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error:&error) ? LAPolicy.DeviceOwnerAuthenticationWithBiometrics : LAPolicy.DeviceOwnerAuthentication)
        } else {
            // Fallback on earlier versions
            policy = LAPolicy.DeviceOwnerAuthenticationWithBiometrics
        }
        if context.canEvaluatePolicy(policy, error:&error) {
            // evaluate
            context.evaluatePolicy(policy, localizedReason: reason, reply: {
                (success: Bool, authenticationError: NSError?) -> Void in

                // check whether evaluation of fingerprint was successful
                if success {
                    okHandler()
                } else {
                    // fingerprint validation failed
                    // get the reason for validation failure
                    var failureReason = "unable to authenticate user"
                    if let code = error?.code {
                        switch code {
                        case LAError.AuthenticationFailed.rawValue:
                            failureReason = "authentication failed"
                        case LAError.UserCancel.rawValue:
                            failureReason = "user canceled authentication"
                        case LAError.SystemCancel.rawValue:
                            failureReason = "system canceled authentication"
                        case LAError.PasscodeNotSet.rawValue:
                            failureReason = "passcode not set"
                        case LAError.UserFallback.rawValue:
                            failureReason = "user chose password"
                        default:
                            failureReason = "unable to authenticate user"
                        }
                    }
                    print("validation reason: \(failureReason).");
                    cancelHandler()
                }
            })
        } else {
        }

请帮帮我!

EN

回答 2

Stack Overflow用户

发布于 2016-04-18 09:36:29

你不能。用户必须至少“输入”一次错误的指纹,才能让回退按钮出现。希望苹果在这个功能中增加一个属性。

票数 3
EN

Stack Overflow用户

发布于 2017-10-16 18:29:04

不幸的是,您不能这样做,出于安全和隐私的原因,本地身份验证框架非常有限。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36462897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档