5

I am using LocalAuthentication framework for iOS and have followed the general tutorials from around the web to implement TouchID authentication for my App.

When the app calls context.evaluatePolicy(policy, error:&error) I want to show the user an option to "Enter Password" instead of having the user select "Cancel" to dismiss the dialog box and enter the password.

This is the default behavior in the AppStore app but I cannot get my app to perform the same way. Please see the AppStore screenshot below:

AppStore TouchID Authentication

The code I use is consistent with the various tutorials out there. See code below.

My app launches with the following screen:

My App TouchID authentication

I have searched high and low, on SO and other sites but have not been able to launch my app with "Show Password". When I use an unregistered finger to authenticate the LA dialog box changes to "Try again" and has the "Show Password" button.

        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 {
        }

Please help!

geekay
  • 215
  • 2
  • 7

2 Answers2

3

You can't. The user has to "enter" at least once a wrong fingerprint to let the fallback button appear. Hopefully apple add a property in the feature.

1

Unfortunately you can't do this, The local authentication framework is extremely limited for security and privacy reasons.

Amr Angry
  • 3,711
  • 1
  • 45
  • 37