1

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

}
Hussein
  • 487
  • 6
  • 22
  • Possible duplicate of [Programmatically get own phone number in iOS](http://stackoverflow.com/questions/193182/programmatically-get-own-phone-number-in-ios) – Code Different Apr 03 '17 at 14:02
  • 1
    The short answer is "no way". You have to ask the user to enter it manually. There are private APIs to access the user's phone number, but then Apple will reject your app – Code Different Apr 03 '17 at 14:04
  • I just want to get the number that the user entered manually in Digits API screen so I can create my own database – Hussein Apr 03 '17 at 14:07

1 Answers1

0

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

Hussein
  • 487
  • 6
  • 22