LocalAuthentication structure - how do I get the "Enter Password" to be shown on the first call

I use the LocalAuthentication environment for iOS and follow the general tutorials from around the web to implement TouchID authentication for my application.

When the application calls context.evaluatePolicy (policy, error: & error) I want to show the user the option "Enter password" instead of the user choosing "Cancel" to close the dialog box and enter the password.

This is the default behavior in the AppStore application, but I cannot get my application to do the same. See AppStore screenshot below:

AppStore TouchID Authentication

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

My application starts from the following screen:

My App TouchID authentication

I searched high and low on SO and other sites, but could not launch my application using "Show Password". When I use an unregistered finger to authenticate the LA dialog box, change it to "Try Again" and click 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!

+5
source share
2 answers

You can not. The user must "enter" at least once an erroneous fingerprint for the return button to appear. We hope that the apple will add a property to this function.

+3
source

Unfortunately, you cannot do this. Local authentication is extremely limited for security and privacy reasons.

+1
source

Source: https://habr.com/ru/post/1246592/


All Articles