我正在使用多个窗口设置我的应用程序。它运作良好。但是当我从跳板打开我的应用程序时,它每次都会创建一个新窗口。
我正在使用最新的 Xcode 和 iPadOS 13.0 测试版。我所有的视图控制器、视图等都是以编程方式制作的。我唯一的故事板是 LaunchScreen。
信息列表
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default</string>
<key>UISceneDelegateClassName</key>
<string>ComicReader.SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
AppDelegate.swift
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
UISceneConfiguration(name: "Default", sessionRole: connectingSceneSession.role)
}
SceneDelegate.swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = scene as? UIWindowScene else { return }
window = UIWindow(windowScene: scene)
window?.rootViewController = DelegateHelper.rootViewController()
window?.makeKeyAndVisible()
}
}
在Apple的Gallery示例中,如果打开应用程序,滑动到主屏幕,然后再次打开应用程序,我就回到了原来的位置,没有scene(_:willConnectTo)
再次调用。在我自己的应用程序上,scene(_:willConnectTo)
每次打开应用程序时都会调用它,并且放置断点向我表明,我确实在每次启动时收到了不同的 UIScene 和 UISceneSession 对象。
我没有显示任何 NSUserActivity 代码,因为我首先是因为我还没有任何状态恢复。实施它不会改变任何事情。
如果你有一些想法,我很高兴读到你!