如何以编程方式设置InitialViewController故事板?我想根据某些条件打开我的故事板到不同的视图,这些条件可能因发布而异.
在Xcode 11中,我从Single View App模板创建了一个新的应用程序项目。我希望此应用程序可以在iOS 12和iOS 13中运行。但是,当我将部署目标切换到iOS 12时,出现了很多错误消息,如下所示:
UIWindowScene仅在iOS 13或更高版本中可用
我该怎么办?
我需要支持 iOS 12 和 iOS 13。
我应该在AppDelegate和之间复制代码SceneDelegate吗?
例如:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = HomeViewController()
window.makeKeyAndVisible()
self.window = window
}
Run Code Online (Sandbox Code Playgroud)
和
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = HomeViewController()
window.makeKeyAndVisible()
self.window = window
return true
}
Run Code Online (Sandbox Code Playgroud)
如果我不这样做,在 1 个版本中我最终会出现黑屏,但是如果我这样做并以 的viewDidLoad方法打印, …