swift - touchID 需要很长时间才能加载
swift - touchID takes long time to load
我正在努力将 touchID 集成到我的应用程序中。这个过程相当简单,但即使只使用我的虚拟数据,它在验证我的指纹后,执行它的任务之前也需要大约 5 秒。
这是我的代码:
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")
}
})
}
}
即使使用虚拟数据,也需要很长时间。
当我正常登录时,通过在我的输入字段中输入电子邮件和密码,signIn() 函数立即 运行s。
看看是不是这个问题。我尝试用 2 行简单地将我带到正确的 viewController 来替换它。但是在验证我的指纹后仍然需要几秒钟。
我知道这不是 phone,也不是 touchID。立即导致它 运行s my println("successfull signin with touchID") 。这是之后发生的事情,由于某种原因需要几秒钟才能到达 运行?
如果能帮助解释这一点,我们将不胜感激!
文档指出:
This method asynchronously evaluates an authentication policy.
您是 运行 UI 非主线程上的代码。包装您的代码以使其在主线程上执行:
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")
}
})
}
}
我正在努力将 touchID 集成到我的应用程序中。这个过程相当简单,但即使只使用我的虚拟数据,它在验证我的指纹后,执行它的任务之前也需要大约 5 秒。
这是我的代码:
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")
}
})
}
}
即使使用虚拟数据,也需要很长时间。
当我正常登录时,通过在我的输入字段中输入电子邮件和密码,signIn() 函数立即 运行s。
看看是不是这个问题。我尝试用 2 行简单地将我带到正确的 viewController 来替换它。但是在验证我的指纹后仍然需要几秒钟。
我知道这不是 phone,也不是 touchID。立即导致它 运行s my println("successfull signin with touchID") 。这是之后发生的事情,由于某种原因需要几秒钟才能到达 运行?
如果能帮助解释这一点,我们将不胜感激!
文档指出:
This method asynchronously evaluates an authentication policy.
您是 运行 UI 非主线程上的代码。包装您的代码以使其在主线程上执行:
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")
}
})
}
}