Wes*_*st1 10 lifecycle info.plist swift swiftui uiscenedelegate
我有一个 SwiftUI/SpriteKit 项目。在一次充满错误的更改包标识符的任务中,我决定创建一个新项目并复制我的文件。
现在我已经有了这个包含所有旧文件的新项目,但是当我运行它时,我得到一个空白屏幕,因为我的SceneDelegate
函数scene(_:willConnectTo:options:)
没有被调用。
根据文档,SceneDelegate
如果您对info.plist
. 然而,我已经做了这些改变,但我的SceneDelegate
仍然不起作用。
这是我的相关部分SceneDelegate
:
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
static var mainData = MainData()
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).
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView.environmentObject(SceneDelegate.mainData))
self.window = window
window.makeKeyAndVisible()
}
}
//...more stuff here
}
Run Code Online (Sandbox Code Playgroud)
问:
为什么我不SceneDelegate
工作?我究竟做错了什么?
谢谢你!
Wes*_*st1 40
我不知道为什么我的SceneDelegate
不起作用,但我做了两件事:
我SceneDelegate
现在按预期工作。
归档时间: |
|
查看次数: |
4603 次 |
最近记录: |