Is the UISceneDelegate scene(_:openURLContexts:) method ever called on a specific scene or just the "first"?

I know that the `UISceneDelegate scene(_:openURLContexts:)` delegate method is meant as the `UIScene` equivalent of the `UIApplicationDelegate application(_:open:options:)` delegate method. But an app can have multiple active scenes while only one will have this delegate called at a time and it always seems to be the "first" scene.


Is there any condition or action that will result in a specific scene (and not just the "first" one) having its `openURLContexts` delegate called or did this turn out to be a flawed design? What am I missing?


Let me clarify the situation with an example.


You have an app that supports multiple scenes in iPadOS. The user is actively using two side-by-side scenes for your app. There may even be some disconnected scenes in the background. Either way, assume there are multiple scenes.


Let's also say that your app can open files of certain types. The user switches from your app to the Files app or just about any app that lets you share a file. In the other app you select a file and choose to open it with your (multi-scene) app.


At this point your app is put back in the foreground and the `openURLContexts` delegate is called on just one of the currently active scenes in your app.


The same issue arises if your app supports a custom URL scheme and your app is launched (or brought back to the foreground) via its custom URL scheme.


So what's the point of this being done on the scene delegate? There are multiple scenes. Only one has this delegate called. Depending on the needs of your app, you probably only want to handle this file in one specific scene but it may not be the scene whose delegate was called. You need to write code to go through the existing scenes and determine which one should actually handle the file, regardless of the scene that was called.


Given this, wouldn't it have been better to just call the `UIApplicationDelegate` to handle the open URL request? Or, as stated in my original question in the second paragraph, are there conditions that call the delegate on a specific scene?

Accepted Reply

You can set a predicate to UIScene.activationConditions to determine which scene handles an event in your application (and becomes active, if needed). More information can be found on UISceneActivationConditions.
The behavior mentioned above is described in WWDC 2019: Session 259 - Targeting Content with Multiple Windows.

Replies

You can set a predicate to UIScene.activationConditions to determine which scene handles an event in your application (and becomes active, if needed). More information can be found on UISceneActivationConditions.
The behavior mentioned above is described in WWDC 2019: Session 259 - Targeting Content with Multiple Windows.