Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set App Entry point programmatically in AppDelegate

In my appdelegate I want to check if globUs.hasName. If it does I want the Entry Point of the app to be my main storyboard. If it does not I want the Entry Point of the app to be my newUser storyboard. How do I set the entry point of the app? If I can't, what is the most effective way to implement this functionality?

like image 299
Gabe Spound Avatar asked Feb 11 '17 01:02

Gabe Spound


1 Answers

Consider not having an entry point. Then, in appDelegate, test for your variable and choose the appropriate storyboard accordingly. Then show the view controller from that storyboard.

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

    if globUs.hasName {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "FirstMainVC")
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = new
        self.window?.makeKeyAndVisible()
    }
    else {
        let storyboard = UIStoryboard(name: "NewUser", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "FirstNewUserVC")
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = welcomeVC
        self.window?.makeKeyAndVisible()
    }

    return true
}
like image 56
Shades Avatar answered Sep 19 '22 18:09

Shades