Group Group Group Group Group Group Group Group Group

Coordinator Pattern (c. 23): Handling launch actions when using App Coordinator

I am using the Coordinator Pattern to manage the overall app architecture as outlined in the tutorial project for Chapter 23.

The App Coordinator has a Splash View Controller that mimics the Launch Screen to be displayed while it determines which child coordinator to present, Onboarding Coordinator or Home Coordinator respectively.

If the user launches the app normally (without any Launch Options), the App Coordinator will use its normal logic to determine which child coordinator to present. If the user launches the app with a Launch Option, such as a URL they’ve clicked, that takes precedence and is passed to the App Coordinator which uses it to determine which child coordinator to present and passes it down the stack.

That seems easy enough – my problem occurs when the app is already running and the App Coordinator is presenting either two of the child coordinators, but the user re-opens the app through a URL and the App Delegate receives the application: openURL: options call.

What is the cleanest way to handle this such that this information is passed to the App Coordinator which then uses it to present the correct screen of the correct child coordinator, but with the option to return to wherever the user was at before?

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

As an idea, why not have a top-level coordinator, e.g. call it AppCoordinator/RootCoordinator/whatever, that itself is only responsible for displaying child coordinators?

You can then have these methods:

init(with options:)

func handle(options: )

Wherein, init(with options:) could call handle(options:).

handle(options:) would determine which child coordinator to create and then call presentChild: with it.

Hopefully, this gives you an idea the very least to try. :]

If you come up with a solution that works for you, feel free to share it so others can learn from your experience!