I'm setting up my app with multiple windows. It's working well. But when I open my app from the springboard, it creates a new window every time.
I'm on the latest Xcode & iPadOS 13.0 betas. All my viewcontrollers, views, etc, are made programmatically. My only storyboard is the LaunchScreen.
Info.plist
<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()
}
}
In the Apple's Gallery sample, if open the app, swipe to the home screen, then open the app again, I'm back where I were, without calling scene(_:willConnectTo)
again. On my own app, scene(_:willConnectTo)
is called each time that I open the app, and putting breakpoints shows me that I indeed receive differents UIScene & UISceneSession objects at each launch.
I didn't show any NSUserActivity code because I first though it was because I didn't have any state restoration yet. Implemeting it doesn't change a thing.
If you have some ideas, I'm happy to read you!