繁体   English   中英

AppDelegate 到 SceneDelegate

[英]AppDelegate to SceneDelegate

我有一个我正在工作的旧项目,它没有sceneDelegate。 我的 AppDelegate didFinishLaunchingWithOptions 看起来像:

import Firebase
import customFramework 
    
class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
        
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            
            FirebaseApp.configure()
            
            // Create window
            window = UIWindow(frame: UIScreen.main.bounds)
            window?.rootViewController = ViewController()
            window?.makeKeyAndVisible()
            
            
            
            customFrameworkManager.shared.start()
            
            return true
        }
    .
    .
    .

我想转换这段代码,因此决定创建一个新的新项目,但现在有一个场景委托的实现。 我尝试改变我的 func 场景(willConnectTo),它看起来像:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
            // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
            // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
            // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
        
        
        if let windowScene = scene as? UIWindowScene {
            self.window = UIWindow(windowScene: windowScene)
            
            self.window!.makeKeyAndVisible()
            
         
                }
        customFrameworkManager.shared.start()
    }

但是 customFramework 没有在应用程序中启动。 谁能建议我在这里做错了什么。 任何帮助,将不胜感激。 谢谢

在您的 sceneDelegate 中,我没有看到 rootViewController,请尝试这样:

guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
let controller = ViewController()
window.rootViewController = controller
self.window = window
window.makeKeyAndVisible()
customFrameworkManager.shared.start()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM