Search code examples
iosswiftios-universal-links

When using universal links, the "continue" calls are now only called in the SceneDelegate - can they be called in the AppDelegate?


These days in iOS apps,

AppDelegate#willContinueUserActivityWithType and

AppDelegate#continue#restorationHandlers

are simply it seems not / never? called when you click a universal link.

Instead,

SceneDelegate#continue and

SceneDelegate#willContinueUserActivityWithType

are called.

That's fine but,

  • is there in fact a way to get the AppDelegate called ("like in the old days") rather than the SceneDelegate? What causes the duality? Is there a danger of them BOTH being called?

  • are there perhaps some circumstances where SceneDelegate is NOT called, and it does revert to AppDelegate being called?

Can you nowadays reliably rely on SceneDelegate being called with universal links, and forget about AppDelegate?


Solution

  • iPadOS 13 introduced the concept of multiple windows and the scene delegate. Each window has its own separate scene and scene delegate. Apps on iPad may choose to support multiple windows/scenes. When run on iPhone, there is always only one scene (true up to and including iOS 17, but maybe one day…)

    Once an app had been converted to use the new scene architecture as part of adding support for iOS 13, or if it was created in a version of Xcode that supported it by default, many old app delegate methods were effectively replaced by similar scene delegate methods. Some app delegate methods are still called because they refer to the entire app rather than specific windows/scenes.

    The only way in which an app that supports the scene architecture will use the app delegate for the methods that have been superseded by scene delegate versions is if it is executed on a device running iOS/iPadOS 12 or earlier. In the few years that followed iOS 13, apps which still supported older iOS versions needed to implement both the app and scene delegate methods to handle running on pre- or post-iOS 13 devices.

    It is possible to remove support for the scene architecture for newly-created apps but I recommend against it. We should be looking forward, not backwards.

    Can you nowadays reliably rely on SceneDelegate being called with universal links, and forget about AppDelegate?

    Yes. Any method which has both scene and app delegate versions will only ever use the scene version.