-1

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?

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    See Apple's sample about about state restoration - https://developer.apple.com/documentation/uikit/uiscenedelegate/restoring_your_app_s_state - The readme and the code have a lot of good comments that cover all of this. In short, iOS 13.0+ in an app that supports scenes will need to use the scene delegate methods at all times. – HangarRash Jun 14 '23 at 17:19
  • 1
    Apple also has a document on handoff - https://developer.apple.com/documentation/foundation/task_management/implementing_handoff_in_your_app - but sadly it's not updated for iOS 13.0+ and scenes. So it is a terrible document for looking into what is called. For me, I created a new project with scenes, implemented every app and scene delegate method and added lots of print statements to learn what is called and what isn't. – HangarRash Jun 14 '23 at 17:22
  • How is this different from eg https://stackoverflow.com/questions/67476876/deep-links-with-appdelegate-and-scenedelegate – matt Jun 14 '23 at 19:48
  • that question explains *how to* use scene delegate. this question states *how to* use scene delegate, and then asks four (critical) questions. *(is there in fact a way to get the AppDelegate called 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?)* (Notice the headline title) All four questions are perfectly answered by the answer present here, phew – Fattie Jun 22 '23 at 13:18

1 Answers1

1

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.

Geoff Hackworth
  • 2,673
  • 1
  • 16
  • 16
  • I'm wondering, is it still absolutely the case that `AppDelegate#application#didFinishLaunchingWithOptions` is called, when an app launches, 100% reliably in every flavor of phone/pad app ???!! or is that on the way out?? – Fattie Jun 22 '23 at 13:11