LocalAuthentication框架 - 如何在第一次调用时显示"输入密码"

gee*_*kay 6 objective-c ios touch-id swift

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

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

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

AppStore TouchID身份验证

我使用的代码与各种教程一致.见下面的代码.

我的应用程序启动时显示以下屏幕:

我的App TouchID身份验证

我在SO和其他网站上搜索过高和低,但是无法使用"显示密码"启动我的应用程序.当我使用未注册的手指来验证LA对话框时,请更改为"再试一次"并显示"显示密码"按钮.

        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 {
        }
Run Code Online (Sandbox Code Playgroud)

请帮忙!

小智 3

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