生命周期的变化
iOS13之前
Appdelegate的职责全权处理App生命周期和UI生命周期;
iOS13之后:
Appdelegate的职责是:
1、处理 App 生命周期
2、新的 Scene Session 生命周期
iOS13之后UI生命周期由新的 Scene Session负责
初始化window的变化
新的xcode默认是storyboard加载,如果要改为代码加载需要在Scene Session中添加
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
self.window.rootViewController = [UITabBarController new];
[self.window makeKeyAndVisible];
}
但目前Scene Session只支持iOS13,兼容以前的版本,做版本判断,或者直接删掉Scene Session,回到熟悉的iOS13之前,需要如下步骤:
1.删除info.plist中的Application Scene Manifest,删除MainInterface
2.删除Appdelegate中UISceneSession的相关代码,并添加如下代码
@property (strong, nonatomic) UIWindow *window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = UIColor.whiteColor;
self.window.rootViewController = BaseTabBarController.new;
[self.window makeKeyAndVisible];
return YES;
}