iOS 13 app requests a new scene each time the app icon is tapped

1.2k Views Asked by At

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!

1

There are 1 best solutions below

0
On BEST ANSWER

So, I'm looking for this since last week. Today, I decided to comment all my AppDelegate, SceneDelegate, & keep only one scene configuration in Info.plist. Rewrite AppDelegate & SceneDelegate from the default template to mine progressively.

It works on first try with default template. I rewrite everything identical… stills works.

The problem? The "Default" configuration in Info.plist in UIWindowSceneSessionRoleApplication array was "Item 1", not "Item 0". git stash everything and only reorder that made it work too.

I hope this helps someone.