自iOS 13 Beta 3起,我的应用仅显示黑色窗口

时间:2019-07-03 15:29:08

标签: swift ios13

这是我的场景委托方法的代码:

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).

    // Use a UIHostingController as window root view controller
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)

    // Override point for customization after application launch.
    let context = AppDelegate.shared.persistentContainer.viewContext
    context.automaticallyMergesChangesFromParent = true

    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}

1 个答案:

答案 0 :(得分:3)

这是原始默认设置。从beta 3开始,windows需要像这样初始化:

    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView(coordinator:coord, model:store))
        self.window = window
        window.makeKeyAndVisible()
    }