无法在回调后成功执行

时间:2017-04-23 10:20:08

标签: ios swift3

当我点击一个名为getVPhoneNumber的函数时,我正在尝试使用动作创建一个SignUp按钮。在电话验证成功后,它会使用popover VC启动名为Digits by Fabric的电话验证API,完成时应将电话号码包含为字符串,并且SignUp btn中的result var应该接收该号码,以便它可以performSeague到另一个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

注意:在电话验证过程完成之前,控制台中不会打印“Going To SignUp VC”,这就是我想要的,但是由于它通过打印该语句继续该过程,为什么它不启动PerformSegue?为什么只打印声明。

提前致谢,如果我的一些解释不明确,我很抱歉。

1 个答案:

答案 0 :(得分: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窗格中)。