【问题标题】:How to get user's phone number?如何获取用户的电话号码?
【发布时间】:2017-04-03 12:36:11
【问题描述】:

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

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

找到了这个 sn-p,但又不知道在哪里实现它。

这是我的手机验证登录按钮操作:

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

}

【问题讨论】:

  • 简短的回答是“没办法”。您必须要求用户手动输入。有私有 API 可以访问用户的电话号码,但苹果会拒绝你的应用
  • 我只想获取用户在 Digits API 屏幕中手动输入的数字,以便创建自己的数据库

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


【解决方案1】:

所以我在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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 2011-09-05
    • 1970-01-01
    相关资源
    最近更新 更多