0

I'm trying to skip my loginViewController when the app launches when the user is currently logged in to parse.

But I can't connect my loginViewController to the appDelegate were the didLaunchApp function is.

So when the app launches the app needs to check if there is a parse user logged in. When it is "true", he needs to skip the loginViewController, else he needs to show the loginViewController when the app launches.

Can you guys help me out?

rici
  • 234,347
  • 28
  • 237
  • 341
  • Possible duplicate of [Conditionally start at different places in storyboard from AppDelegate](http://stackoverflow.com/questions/8451975/conditionally-start-at-different-places-in-storyboard-from-appdelegate) – danh Dec 30 '15 at 17:25
  • i understand the logic but how can i do this in swift? how can i set the loginviewcontroller to the app delegate and say that the loginviewcontroller(animated: false) when the user is already logged in @danh – Quinn Donkers Dec 30 '15 at 17:39
  • `self.window.rootViewController.performSegueWithIdentifier("the identifier", sender:self)` – danh Dec 30 '15 at 17:45

1 Answers1

0

Put this code in your App Delegate, in the didFinishLaunchingWithOptions function. Of course, your own view controllers will go in place of mine:

let currentUser = PFUser.currentUser()
    if currentUser != nil {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let controller1 = storyBoard.instantiateViewControllerWithIdentifier("yourViewControllerIdentifier") as! YourViewController
        self.window?.rootViewController = controller1
        self.window?.makeKeyAndVisible()
    }

basically the idea is if the current user is not nil, you will make the root view controller a different one (the controller that you specify just above), and the app will start from there as the storyboard entry point.

To use this method you have to give your view controller (the one you want to skip to if the user is logged in) a storyboard identifier. Go to the panel to the far right to do this, and under "Storyboard ID" give it a name. pass this name in as the string where I put "yourViewControllerIdentifier"

Then, just cast that to whatever the name of the class is that represents that view controller.

jjjjjjjj
  • 4,203
  • 11
  • 53
  • 72
  • Thnx but now when i log out i use : @IBAction func LogOutButton(sender: AnyObject) { PFUser.logOut() self.navigationController?.popToRootViewControllerAnimated(true) } but this is not working anymore is her an other way ? – Quinn Donkers Jan 01 '16 at 22:58