Home How to load next viewController after facebook login without going back to login viewController in swift
Reply: 0

How to load next viewController after facebook login without going back to login viewController in swift

user2223
1#
user2223 Published in May 28, 2018, 5:05 am

I am struggling with a problem, I have integrated my app with facebook to login, when I try to login with facebook and after sucessfully login i want to go next viewcontroller but it comeback to same login screen then goes to next viewcontroller, my requirement is that after facebook login it should display next viewController that is [presentedViewController] in my code, I aslo set the delegate to facebook button but before executing func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result:

FBSDKLoginManagerLoginResult!, error: Error!) {} method displayed the login screen.

AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

           FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

      return true
}  

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {        

    let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

            return handled

}

ViewController.swift:

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {

    print("Did log out of facebook")

}



func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {   

    if error != nil {

        print(error)

        return

    }       

    if let userToken = result.token{

        print("Token=\(FBSDKAccessToken.current())")

        let presentPage = self.storyboard?.instantiateViewController(withIdentifier: "PresentedViewController") as! PresentedViewController

        let presentPageNav = UINavigationController(rootViewController: presentPage) 

        let appDelegate = UIApplication.shared.delegate as! AppDelegate

        appDelegate.window?.rootViewController = presentPageNav

    }

}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30465 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO