How get rootViewController with iPadOS multi window (SceneDelegate)?

前端 未结 2 1485
滥情空心
滥情空心 2021-02-05 14:50

I am using Xcode 11 (beta3) and building an app for iOS 13. In my project I created the delegate methods for UIWindowSceneDelegate declaring it in Info.plist. Now I

2条回答
  •  别跟我提以往
    2021-02-05 15:47

    You can access connected scenes using:

    UIApplication.shared.connectedScenes
    

    As per Apple documentation:

    Connected scenes are those that are in memory and potentially doing active work. A connected scene may be in the foreground or background, and it may be onscreen or offscreen.

    Then you can iterate through them and try to get UIWindowScene from there.

    guard let windowScene = (scene as? UIWindowScene) else { return }
    print(windowScene.windows) // This will print windows associated with the scene.
    

    On the other hand, from the view controller you can access the window through the view:

    self.view.window
    

提交回复
热议问题