SWIFT iOS8上:TouchID认证之后进行SEGUE [英] swift iOS8: perform segue after TouchID authentication

查看:142
本文介绍了SWIFT iOS8上:TouchID认证之后进行SEGUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序有两种观点。只要第一个视图加载我执行触摸ID传感器验证(见这个问题):

I have a simple App with two views. As soon as the first view is loaded I'm performing a Touch ID sensor authentication (see also this question):

func testTouchID()
{
  if touchIDContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error:&touchIDError) 
  {
    touchIDContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: {
    (success: Bool, error: NSError?) -> Void in
      if success 
      {
        self.performSegueWithIdentifier("showSecondView", sender: self)
        return;
} else {

通过执行此code中的SEGUE,但第二个观点只是出现了一会儿,然后在App又回到第一个视图。
看来,里面的code canEvalutePolicy 还没有完成,所以导航控制器推第一个视图。

With this code the segue is performed, but the second view just appears for a moment and then the App goes back to the first view. It seems that the code inside canEvalutePolicy is not finished, so the navigation controller push the first view.

我试过几件事情,如:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

NSOperationQueue.mainQueue().addOperationWithBlock

和还这些方法的组合,但我不能够执行SEGUE第二种观点,并留在了第二种观点。

And also a combinations of these method, but I'm not able to perform the segue to the second view and stay in the second view.

谁能帮助?

感谢和最好的,
圭多

Thanks and best, Guido

推荐答案

我能解决这个问题。问题是导航控制器

I was able to solve this issue. The problem was the navigation controller.

我的解决办法:第一种观点不再嵌入导航控制器,它只是有一个SEGUE到第二个视图

My solution: the first view is not anymore embedded in a navigation controller, it just have a segue to a second view.

然后,第二视图是为了有欲视图之间导航行为嵌入在导航控制器(沿与他人的意见)。

Then the second view is embedded in a navigation controller (along with others views) in order to have the navigation behaviour between views that I want.

重要的是要使用 dispatch_async 以负荷导航控制器只要用户验证:

Important is to use dispatch_async in order to "load" the navigation controller as soon as the user authenticates:

if success {
  dispatch_async(dispatch_get_main_queue()) {
    self.performSegueWithIdentifier("xxx", sender: self)

如果没有dispatch_async第二种观点出现,但导航控制器的导航逻辑缺少约15秒。

Without dispatch_async the second view appears but the navigation logic of the navigation controller is missing for around 15 seconds.

这篇关于SWIFT iOS8上:TouchID认证之后进行SEGUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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