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

huangapple go评论66阅读模式
英文:

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

问题

In iOS 应用中,最近的情况是:

AppDelegate#willContinueUserActivityWithType

AppDelegate#continue#restorationHandlers

似乎在点击通用链接时根本没有被调用或从不被调用。

相反,

SceneDelegate#continue

SceneDelegate#willContinueUserActivityWithType

被调用。

这很好,但是:

  • 实际上是否有方法使AppDelegate被调用("就像以前一样"),而不是SceneDelegate?是什么导致了这种二元性?它们两者都被调用的危险吗?

  • 或许在某些情况下,SceneDelegate不会被调用,而会回到调用AppDelegate的情况?

你现在是否可以可靠地依赖于SceneDelegate在通用链接的情况下被调用,而忽略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?

答案1

得分: 1

iPadOS 13引入了多窗口和场景代理的概念。每个窗口都有自己独立的场景和场景代理。在iPad上运行的应用程序可以选择支持多窗口/场景。在iPhone上运行时,始终只有一个场景(直到iOS 17为止是如此,但也许有一天会变化)。

一旦应用程序被转换为在iOS 13中添加对新场景架构的支持的一部分,或者如果它是在默认支持它的Xcode版本中创建的,许多旧的应用程序委托方法实际上被类似的场景委托方法所取代。仍然会调用一些应用程序委托方法,因为它们涉及整个应用程序而不是特定的窗口/场景。

仅当在运行iOS/iPadOS 12或更早版本的设备上执行时,支持场景架构的应用程序才会使用已被场景代理版本取代的应用程序委托方法。在iOS 13之后的几年里,仍然支持旧版本iOS的应用程序需要实现应用程序委托和场景委托方法来处理在iOS 13之前或之后的设备上运行的情况。

可以在新创建的应用程序中移除对场景架构的支持,但我建议不要这样做。我们应该展望未来,而不是回顾过去。

> 现在可以可靠地依赖于通过通用链接调用SceneDelegate了吗,可以不考虑AppDelegate吗?

可以。具有场景和应用程序委托版本的任何方法只会使用场景版本。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月15日 01:09:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476023.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定