简体   繁体   中英

How to get user's phone number?

I have just started using Digits - Twitter API for Phone Number verification, but it seems I'm unable to read the user's Phone number, I'm not sure if there is a function for that or so, but after reading a while I knew that I can do that with a Call back after successful phone verification but no explanation for that !

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

found this snippet but again not sure where to implement it.

HERE is my Action for the login button with phone verification:

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

}

So I found the answer after digging a lot more in Digits Documentations and it was pretty simple, I had to add:

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

In the didTap function, so the complete code will be:

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

}

Here is the Reference I have used: https://docs.fabric.io/apple/examples/cannonball/index.html#sign-in-with-digits

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM