去除SceneDelegate(swift)版

    科技2026-01-03  12

    去除SceneDelegate(swift)版


    新建项目后发现多了SceneDelegate.swift文件,我本来就是一名新手,多了这个文件,表示不是很懂,所以打算去掉它,以后再研究这个SceneDelegate,既然出现了,肯定有他的原因。

    文章目录

    去除SceneDelegate(swift)版一、修改Info.plist二、删除SceneDelegate.swift文件三、修改AppDelegate.swift文件


    一、修改Info.plist

    使用普通文本编辑器,删除以下代码:

    <key>UIApplicationSceneManifest</key> <dict> <key>UIApplicationSupportsMultipleScenes</key> <false/> <key>UISceneConfigurations</key> <dict> <key>UIWindowSceneSessionRoleApplication</key> <array> <dict> <key>UISceneConfigurationName</key> <string>Default Configuration</string> <key>UISceneDelegateClassName</key> <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string> <key>UISceneStoryboardFile</key> <string>Main</string> </dict> </array> </dict> </dict>

    二、删除SceneDelegate.swift文件

    三、修改AppDelegate.swift文件

    注释或删除UISceneSession的生命周期函数 最终代码如下:

    // // AppDelegate.swift // Hello // // Created by pingchas on 2020/10/8. // Copyright © 2020 pingchas. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. self.window = UIWindow(frame: UIScreen.main.bounds) self.window?.backgroundColor = UIColor.white self.window?.rootViewController = ViewController() self.window?.makeKeyAndVisible() return true } // MARK: UISceneSession Lifecycle /*func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. }*/ }
    Processed: 0.017, SQL: 9