Search code examples
iosswifttwitter-digits

How to programmatically segue after successful authentication?


I'm making an app using the Digits framework for users to login with their phone number. With that being said, I've tried to find a way to segue to my next view after user authentication by creating embedding a UINavigationController (into a ViewController) in my storyboard and adding a button that segues into my next View. I realize that this is not the way to segue after successful authentication. Please have a look at my code and let me know what you think/suggest:

func didTapButton(sender: AnyObject) {
    let digits = Digits.sharedInstance()
    let configuration = DGTAuthenticationConfiguration(accountFields: .DefaultOptionMask)
    configuration.phoneNumber = "+345555555555"
    digits.authenticateWithNavigationViewController(navigationController, configuration: configuration, 
            completionViewController:  completionViewController) 
}

Solution

  • Now I understand the problem more, please try this:

    import UIKit
    import DigitsKit
    class LoginViewController: UIViewController {
    
    override func viewDidLoad() {
            let digitsButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
                 if (session != nil) {
                    print("Your Digits User ID is " + session.userID)
                     let map = MapVC()
                    self.presentViewController(map, animated: true, completion: nil)
                 }
                 else {
                    print(error.localizedDescription)
                }
            })
            self.view.addSubview(digitsButton)
        }
    }
    

    Alternatively can use:

    import UIKit
    import DigitsKit
    class LoginViewController: UIViewController {
    
    override func viewDidLoad() {
        let digitsButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
            if (session != nil) {
                print("Your Digits User ID is " + session.userID)
                self.performSegueWithIdentifier("mapVC", sender: self)
            }
            else {
                print(error.localizedDescription)
            }
        })
        self.view.addSubview(digitsButton)
    }
    }
    

    I hope this works :)