2017-04-23 68 views
0

我试图做一个带有操作的注册按钮,当按钮点击一个名为getVPhoneNumber的函数启动时。并且在电话验证成功后,它启动一个名为Digits by Fabric的电话验证API,电话验证成功后,该电话号码将包含电话号码,并且SignUp btn中的result var应该接收该号码,以便它可以对另一个VC执行。回调后无法执行成功返回

的问题是它不performSegue,只是停留在

登录视图控制器:

func getVPhoneNumber(completion: @escaping (_ result: String)->()) { 

     let configuration = DGTAuthenticationConfiguration(accountFields: .defaultOptionMask) 

     configuration?.appearance = DGTAppearance() 
     configuration?.appearance.backgroundColor = UIColor.white 
     configuration?.appearance.accentColor = UIColor.red 

     // Start the Digits authentication flow with the custom appearance. 
     Digits.sharedInstance().authenticate(with: nil, configuration:configuration!) { (session, error) in 
      if session != nil { 

       //Print Data 
       print(session?.phoneNumber!) 
       print(session?.userID!) 

       //Assign Value to global var vPhoneNumber. 
       self.vPhoneNumber = session?.phoneNumber! 

       print("TESTING COMPLETION") 
       completion((session?.phoneNumber!)!) 

      } else { 
       print("Error") 
      } 

     } 

    } 

//SignUp Button: 

    @IBAction func signUpPressed(_ sender: Any) { 

     getVPhoneNumber() { (result) ->() in 
      // do stuff with the result 
      print(result) 

      print("Going To SignUp VC") 
      self.navigateToMainAppScreen() 

     } 
    } 

//NavigateToMainApScreen Function 

    fileprivate func navigateToMainAppScreen() { 
     performSegue(withIdentifier: "toSignUpVC", sender: nil) 
    } 

故事板概述:

storyboard

注:“在电话验证过程完成之前,不会在控制台中打印“正在注册VC” ed,那就是我想要的,但是因为它通过打印该声明来继续这个过程,为什么它没有启动PerformSegue?为什么只打印声明。

在此先感谢,如果我的某些解释不明确,我很抱歉。

+0

所以唯一的问题是segue没有执行?其他一切按预期工作?我们能否看到您的'navigateToMainAppScreen'功能? :) –

+0

是的,只有海牙没有执行,其他一切按预期工作,我现在要添加'navigateToMainAppScreen'代码:) –

+1

你在主线程中调用performSegue吗? –

回答

0

试试这个:

fileprivate func navigateToMainAppScreen() { 
    DispatchQueue.main.async { [unowned self] in 
     self.performSegue(withIdentifier: "toSignUpVC", sender: nil) 
    } 
} 

编辑: 从注释"2017-04-23 12:31:39.127 b-Donor[6365:130139] Warning: Attempt to present <UINavigationController: 0x7fc2fb878600> on <DGTNavigationViewController: 0x7fc2fa85a600> whose view is not in the window hierarchy!错误表明您的自定义DGTNavigationViewController没有被正确使用代替UINavigationController,请如果在导航控制器检查故事板设置自定义DGTNavigationViewController类正确地(在最右边的XCode窗格中)。

+0

好吧,当我更新我的代码为你的,我在控制台上得到了:'“2017-04-23 12:31:39.127 b-捐助者[6365:130139]警告:试图在上呈现,其视图不在窗口层级中!并且未执行seague –

+0

您需要给出一些上下文,涉及你的视图控制器(又名在哪些类中定义这些方法) –

+0

检查我的更新 –