首先下载我的应用程序时,我想推送一个不同的视图控制器(例如教程视图控制器),然后再次打开后,我想在启动时推送我的普通视图控制器。快速地,我推送视图控制器的方式如下:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = ViewController()
window!.makeKeyAndVisible()
return true
}
从直觉上讲,也许是这样的:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
if firstRun == true {
window!.rootViewController = LaunchViewController()
window!.makeKeyAndVisible()
} else {
window!.rootViewController = ViewController()
window!.makeKeyAndVisible()
}
return true
}
答案 0 :(得分:1)
您可以尝试将该状态保存到UserDefaults
if !UserDefaults.standard.bool(forKey: "LaunchedBefore") {
window!.rootViewController = LaunchViewController()
UserDefaults.standard.set(true, forKey: "LaunchedBefore")
} else {
window!.rootViewController = ViewController()
}
window!.makeKeyAndVisible()