Safari Safari - 5 months ago 30
Objective-C Question

Different flow in storyboard

I have a question about iOS Storyboard.
In my storyboard I have my flow:

  1. Navigation Controller;

  2. Login View Controller;

  3. Detail View Controller;

This is the regular flow if there isn't a valid user session.
When I start the app I need to check if there is a valid user session. In this case I need to visualize directly the 3° (Detail View Controller)
I'm not sure but I think that I need to make the check about user session in my Appdetegate. How can I load, in this case, directly the 3° View Controller?

Answer Source


I think what you can do is not check a valid session at all. Here is what I think

1) Create a BOOL called isUserSignedIn that is initially set to NO and save that in you NSUserDefaults. (AppDelegate didFinishLaunchingWithOptions method)

2) Once user makes a valid Login set the BOOL to YES. Save BOOL in NSUserdefaults

3) When user logs out set BOOL to NO

4) Everytime the user opens the app. In AppDelegate's didFinishLaunchingWithOptions check of the BOOL is yes or no. if no loads LoginViewController. if yes do nothing.

This is how I'd do it. Always save every BOOL changes in NSUserdefaults and loads from there.

SOLUTION 2 But if you want to load your DetailViewController in your AppDelegate use this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    //check your login session here…

    //if session ok loads DetailViewController
    DetailViewController* detail = [[DetailViewController alloc] init];
    [self.window.rootViewController presentViewController:detail
    //if not 
    // do something..

    return YES;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download