Xcode11 新建项目注意点

Xcode11 对应的iOS系统为 iOS13

Xcode11 新建项目时会多出一个SceneDelegate
这个类里面的代码只有 iOS13系统的手机才会执行,

当启动方式采用手动创建window设置rootViewController时, Xcode11window初始化方式与以前有所不同

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不会生效。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容