Xcode11 对应的iOS系统为 iOS13
Xcode11 新建项目时会多出一个SceneDelegate
类
这个类里面的代码只有 iOS13系统的手机才会执行,
当启动方式采用手动创建window
设置rootViewController
时, Xcode11
的window
初始化方式与以前有所不同
xocede11 需要在 SceneDelegate
类里面给window
添加rootViewController
, SceneDelegate
里面window
是已经创建好了的,不需要再次创建
#import "SceneDelegate.h"
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
self.window.rootViewController = [[BaseTabBarController alloc] init];
[self.window makeKeyAndVisible];
//或者使用下面的代码,
/*
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0,
[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.window.windowScene = (UIWindowScene *)scene;
self.window.rootViewController = [[BaseTabBarController alloc] init];
[self.window makeKeyAndVisible];
*/
}
兼容iOS13以下的版本,需要在AppDelegate
中创建window
设置rootViewController
#import "AppDelegate.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13,*)) {
}else{
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.window.rootViewController = [[BaseTabBarController alloc] init];
[self.window makeKeyAndVisible];
}
return YES;
}
方式二
参照以往的AppDelegate
里面
删除SceneDelegate
代理文件 (可选)
删除 Info.plist
里面的Application Scene Manifest
配置(一定要删除)
删除 AppDelegate代理的两个方法:
application:configurationForConnectingSceneSession:options: application: didDiscardSceneSessions:
这两个方法一定要删除,否则使用纯代码创建的Window和导航控制器UINavigationController不会生效。