【问题标题】:swift iOS8: perform segue after TouchID authenticationswift iOS 8:在 Touch ID 身份验证后执行 segue
【发布时间】:2014-09-29 16:02:08
【问题描述】:

我有一个带有两个视图的简单应用程序。加载第一个视图后,我将执行 Touch ID 传感器身份验证(另请参阅this 问题):

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 {

使用此代码执行 segue,但第二个视图只出现片刻,然后应用程序返回第一个视图。 canEvalutePolicy里面的代码好像没有写完,所以导航控制器推送第一个视图。

我尝试了几种方法,例如:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

NSOperationQueue.mainQueue().addOperationWithBlock

还有这些方法的组合,但我无法执行第二个视图的转场并停留在第二个视图中。

谁能帮忙?

谢谢,最好的, 圭多

【问题讨论】:

    标签: asynchronous swift ios8 segue touch-id


    【解决方案1】:

    我能够解决这个问题。问题出在导航控制器上。

    我的解决方案:第一个视图不再嵌入在导航控制器中,它只是与第二个视图有一个连接。

    然后第二个视图被嵌入到导航控制器中(连同其他视图),以便在视图之间具有我想要的导航行为。

    重要的是使用 dispatch_async 以便在用户验证后立即“加载”导航控制器:

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

    如果没有 dispatch_async,第二个视图会出现,但导航控制器的导航逻辑会丢失大约 15 秒。

    【讨论】:

      猜你喜欢
      • 2017-05-10
      • 2023-01-26
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 2020-04-18
      • 2016-12-11
      • 1970-01-01
      • 2019-09-02
      相关资源
      最近更新 更多