赞
踩
在Xcode11前我们可以在
AppDelegate
的钩子didFinishLaunchingWithOptions
进行自定义UIWindow对象。但是Xcode11后自定义UIWindow会报错无法启动APP。
是因为iOS13中AppDelegate
的职责发生了改变: iOS13之前,AppDelegate
全权处理App生命周期和UI生命周期;
iOS13之后,AppDelegate
的职责是: 1、处理 App 生命周期 2、新的 Scene Session 生命周期 那UI的生命周期交给新增的Scene Delegate处理,AppDelegate
不在负责UI生命周期,所有UI生命周期交给SceneDelegate
处理。所以我们需要在SceneDelegate的scene
钩子进行自定义UIWindow初始化。
1.首先我们不仅要删除info.plist中的Main storyboard file base name
还需要删除Application Scene Manifest
下的Storyboard Name
。具体看图
2.然后在 SceneDelegate 中进行初始化UIWindow.
// SceneDelegate.m - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene* )scene]; self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); // 初始化跟视图 UIViewController* ROOTVC = [[ViewController alloc] init]; // 初始化层级导航控制 UINavigationController* ROOTNavigation = [[UINavigationController alloc]initWithRootViewController:ROOTVC]; self.window.rootViewController = ROOTNavigation; // 显示 [self.window makeKeyAndVisible]; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。