ios - AppDelegate 到 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()
推荐阅读
- excel - 提取短语中的多个单词
- c# - C# 复制到剪贴板 - 第三方
- android - Kotlin 无法使用 Putextra 从模型类发送数据
- sql - 通过调用存储过程动态创建临时表
- c - 我的代码似乎不能完美运行(总是相同的消息)
- r - 如何将相关性分析结果放在R中的csv表中
- html - 为什么 box-sizing:border-box 对 img 没有影响?
- python - 如何以超过 60fps 的速度运行 pyglet?
- javascript - 在点击 POST API 时获得随机响应
- mongodb - 如何在mongodb中声明主键?在不知道它的价值的情况下创建索引