swift - touchID 需要很长时间才能加载 [英] swift - touchID takes long time to load

查看:31
本文介绍了swift - touchID 需要很长时间才能加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将 touchID 集成到我的应用程序中.这个过程相当简单,但即使只是使用我的虚拟数据,它在验证我的指纹后也需要大约 5 秒钟,然后才能执行任务.

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.

这是我的代码:

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.

当我正常登录时,通过在输入字段中输入电子邮件和密码,signIn() 函数会立即运行.

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

看看是不是有问题.我尝试用 2 行替换它,只需将我带到正确的 viewController.但是验证我的指纹后仍然需要几秒钟的时间.

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.

我知道这不是电话,也不是 touchID.因为它立即运行我的 println("successfull signin with touchID") .之后是什么,出于某种原因,它需要几秒钟才能运行?

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!

推荐答案

文档说明:

此方法异步评估身份验证策略.

This method asynchronously evaluates an authentication policy.

您正在非主线程上运行 UI 代码.包装您的代码以使其在主线程上执行:

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")
        }
    })
}

}

这篇关于swift - touchID 需要很长时间才能加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆