swift – touchID takes long time to load

I’m working on integrating touchID into my application. The process was fairly simple, but even just using my dummy data, it takes about 5 seconds after it authenticated my fingerprint, before it performs it’s task.

Here’s my code:

  • iOS swift NumberFormatter decimal style localization
  • How Shazam or Sound Hound works?
  • Objective-C Sort String Date Array
  • libobjc.A.dylib compile error on iOS 4.3
  • State of WKWebView on Cordova iOS 9?
  • “Ambiguous reference to member map” from concrete type
  • func requestFingerprintAuthentication() {
        let context = LAContext()
        var authError: NSError?
        let authenticationReason: String = "Login"
    
        if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
            context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: authenticationReason, reply: {
                (success: Bool, error: NSError?) -> Void in
                if success {
                    println("successfull signin with touchID")
                    self.emailInputField.text = "john.doe@gmail.com"
                    self.passwordInputField.text = "password"
                    self.signIn(self.signInButton)
                } else {
                    println("Unable to Authenticate touchID")
                }
            })
        }
    }
    

    even with the dummy data, it takes waaay too long.

    When I login normally, by typing the email and the password into my inputfields, the signIn() function runs instantly.

    To see if it was a problem with that. I tried replacing that, with 2 lines that simply takes me to the correct viewController. But it still takes several seconds after it’s authenticated my fingerprint.

    I know it’s not the phone, nor touchID. Cause it runs my println(“successfull signin with touchID”) immediately. It’s what comes after that, that for some reason takes several seconds for it to run?

    Any help explaining this would be greatly appreciated!

    Solutions Collect From Internet About “swift – touchID takes long time to load”

    The documentation states:

    This method asynchronously evaluates an authentication policy.

    You are running UI code on a thread that is not the main. Wrap your code to get it to perform on the main thread:

    func requestFingerprintAuthentication() {
    let context = LAContext()
    var authError: NSError?
    let authenticationReason: String = "Login"
    
    if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
        context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: authenticationReason, reply: {
            (success: Bool, error: NSError?) -> Void in
            if success {
                NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                    println("successfull signin with touchID")
                    self.emailInputField.text = "john.doe@gmail.com"
                    self.passwordInputField.text = "password"
                    self.signIn(self.signInButton)
                })
            } else {
                println("Unable to Authenticate touchID")
            }
        })
    }
    

    }