2017-04-23 70 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

檢查我的更新 –