2017-04-03 74 views
1

我剛剛開始使用Digits-Twitter API進行電話號碼驗證,但似乎無法讀取用戶的電話號碼,我不確定是否有該功能,但在閱讀一段時間後我知道我可以在成功通過電話驗證後回撥電話,但沒有解釋!如何獲取用戶的電話號碼?

AuthConfig.Builder authConfigBuilder = new AuthConfig.Builder() 
       .withAuthCallBack(callback) 
       .withPhoneNumber(phoneNumberOrCountryCodeFromMyActivity) 

找到這個片段,但又不知道在哪裏實施它。

這是我行動的登錄按鈕使用電話驗證:

fileprivate func navigateToMainAppScreen() { 
    performSegue(withIdentifier: "signedIn", sender: self) 
} 

@IBAction func tapped(_ sender: Any) { 

    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 { 
      // Navigate to the main app screen to select a theme. 
      self.navigateToMainAppScreen() 

     } else { 
      print("Error") 
     } 
    } 

} 
+0

的可能的複製[編程在iOS自己的電話號碼(http://stackoverflow.com/questions/193182/programmatically-get-own-phone-number- in-ios) –

+1

簡短的回答是「沒有辦法」。你必須要求用戶手動輸入。有私人的API訪問用戶的電話號碼,但然後蘋果將拒絕您的應用程序 –

+0

我只想獲得用戶在Digits API屏幕中手動輸入的號碼,以便我可以創建我自己的數據庫 –

回答

0

所以我找到了答案挖了很多的位數之證件後,這是非常簡單的,我不得不添加:

print(session.phoneNumber) 
print(session.userID) 

在didTap功能,所以完整的代碼將是:

@IBAction func tapped(_ sender: Any) { 

    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) 

      // Navigate to the main app screen to select a theme. 
      self.navigateToMainAppScreen() 

     } else { 
      print("Error") 
     } 
    } 

} 

這是我用過的參考: https://docs.fabric.io/apple/examples/cannonball/index.html#sign-in-with-digits