Paal Aune
Paal Aune

Reputation: 343

Touch ID IOS 10 takes 10 - 15 sec to respond

I`m trying to implement touch ID into my app. I get the touch ID to work, but it takes 10 - 15 sec before I get pushed to the next Viewcontroller. I have searched about the topic, and it seems the solution is to run this in the main thread. I then changed my code to run this as the main thread ( I think ), but the problem is still there. Can anybody see whats wrong?

func logMeIn(){

    performSegue(withIdentifier: "notesVC", sender: self)
}


@IBAction func loginButton(_ sender: Any) {

    let context:LAContext = LAContext()

    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil){
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Log in", reply: { (wasSuccessful, error) in
            if wasSuccessful{
                OperationQueue.main.addOperation({() -> Void in })
                self.logMeIn()
            }
            else {
                self.view.backgroundColor = UIColor.red
            }
        })
    }
}
}

Upvotes: 1

Views: 50

Answers (1)

David Pasztor
David Pasztor

Reputation: 54745

That is not how you run something on the main thread. You need to move all code that needs to run on the main thread inside the closure of addOperation, like this:

if wasSuccessful{
    OperationQueue.main.addOperation({() -> Void in self.logMeIn()})
} 

Or you can also do

DispatchQueue.main.async{
    //write the code you want to run on the main thread here
}

Upvotes: 1

Related Questions