如何获取用户的电话号码?

时间:2017-04-03 12:36:11

标签: ios swift3 xcode8 twitter-digits fabric-digits

我刚刚开始使用Digits - Twitter API进行电话号码验证,但似乎我无法读取用户的电话号码,我不确定是否有这样的功能,但在阅读之后虽然我知道我可以通过电话验证成功后回拨来做到这一点,但没有解释!

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

找到了这个片段但又不确定在哪里实现它。

HERE是我的登录按钮操作,包含电话验证:

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")
        }
    }

}

1 个答案:

答案 0 :(得分:0)

所以我在Digits Documentations中挖掘了很多东西之后得到了答案,这很简单,我不得不补充一下:

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