I've modified my app to create new windows using App Exposé or by dragging out of the dock. But it seems as if my viewcontroller and scene get out of sync. I've verified this by printing the unique persistentIdentifier that comes with every scene session. I'm using storyboards so my scene delegate is rather simple.
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let rootVC = self.window?.rootViewController
dPrint("\(#function) rootVC \(String(describing: rootVC!)) pId \((scene as? UIWindowScene)?.session.persistentIde}ntifier ?? "??" )")
}
}
Here's my info.plist
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
And AppDelegate:
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Based on the name of the configuration iOS will initialize the correct SceneDelegate
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
I delete the app from the simulator to start with a clean scenerio. I open the app and the initial scene gets created. I print its persistentIdentifier and its: 67926371-9D25-46DC-BD52-8D44B1967B33. I use the a bit and the corresponding persistentIdentifier shows. All good!
Now, I go to the home screen, show all windows (only one shows) and select the plus button on the upper right corner to create another scene/window. The new scene gets created and it gets it's own persistentIdentifier: B73F438D-942F-435C-87E7-117BF6E06C79.
I use the app and the corresponding persistentIdentifier (for newly created scene) shows. Now I go to the home screen, show all windows and I select the originally created scene. But now the persistentIdentifier shown is still the one for the secodd scene! After creating the second scene, my UI always shows the persistentIdentifier for the second scene regardless of whih scene is in the foreground.
This is actually the second app I'm adding multi-window support. So, I have some experience doing this. The first app was similar: storyboard based, etc. It works perfectly. I've verified that the persistentIdentifier is suppoed to follow the viewcontroller.
It appears as if the scene and view controllers are out of sync. Why is this happening? What am I missing?