iOS11以后新建工程多了两个文件SceneDelegate.h,SceneDelegate.m,以及AppDelegate.m少了不少方法及window,原来新建的窗口导航根控制器肯定是不可行了,那么如何在新建的项目中适用呢
1.不支持多窗口,使用原理的AppDelegate.m,找到info.list 把Application Scene Manifest干掉.
2.AppDelegate添加widow
3.把新增的- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options 和- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions 方法干掉
4.写上你的代码即可
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13,*)) {
return YES;
} else {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UINavigationController *rootNavgationController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
self.window.rootViewController = rootNavgationController;
[self.window makeKeyAndVisible];
return YES;
}
}
二 如何支持多窗口SceneDelegate写呢?
1.之前info.list 下的Application Scene Manifest保留
2.在SceneDelegate.m下面写,这是iOS13后的
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions )connectionOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.windowScene = (UIWindowScene)scene;
UINavigationController *rootNavgationController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
self.window.rootViewController = rootNavgationController;
[self.window makeKeyAndVisible];
}
3.如果要iOS13前的还需要添加 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13,*)) {
return YES;
} else {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UINavigationController *rootNavgationController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
self.window.rootViewController = rootNavgationController;
[self.window makeKeyAndVisible];
return YES;
}
}