美文网首页
xcode11 新建项目中的SceneDelegate

xcode11 新建项目中的SceneDelegate

作者: ly_chee_ | 来源:发表于2020-06-15 17:32 被阅读0次

    1、Xcode 11 默认是会创建通过 UIScene 管理多个 UIWindow 的应用,工程中除了 AppDelegate 外会多一个 SceneDelegate

    2、AppDelegate和SceneDelegate这是iPadOS带来的新的多窗口支持的结果,并且有效地将应用程序委托的工作分成两部分。info.plist中 Enable Multiple Windows,需要将其设置为“ YES”以支持多个窗口。

    我们可以看下info.plist文件和工程项目文件的变化如图:


    适配方案

    1、如果我们不开发iPadOS多窗口APP,SceneDelegate窗口管理我们可以不需要直接删掉就好了。删除掉info.plist中Application Scene Manifest选项,同时,文件SceneDelegate可删除可不删

    2、相关代码注释掉

    #pragma mark - UISceneSession lifecycle
     - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {        
         return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:  connectingSceneSession.role];
    }

     - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {   
    }   

    //注释掉这两个方法。

    3、Appdelegate新增windows属性

    在APPdelegate.h中添加@property (strong, nonatomic) UIWindow * window; 属性

        ///做完这些就跟以前一样啦。

    相关文章

      网友评论

          本文标题:xcode11 新建项目中的SceneDelegate

          本文链接:https://www.haomeiwen.com/subject/hvjhxktx.html