在AppDelegate中以编程方式设置App Entry点

Gab*_*und 5 startup entry-point ios appdelegate swift

在我的appdelegate中,我想检查一下globUs.hasName.如果是的话,我希望Entry Point应用程序成为我的main故事板.如果不是,我希望Entry Point应用程序成为我的newUser故事板.如何设置应用的入口点?如果我不能,实现此功能的最有效方法是什么?

Sha*_*des 5

考虑没有入口点。然后,在 appDelegate 中,测试您的变量并相应地选择适当的故事板。然后显示该故事板中的视图控制器。

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
}
Run Code Online (Sandbox Code Playgroud)