Xcode 11 deeplink 似乎有所不同,因为它没有从 AppDelegate 调用函数

Xcode 11 deeplink seems to be different since it does not call the function from AppDelegate

我尝试使用 Xcode 11 中的深层链接,但发现该应用未调用

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return true
}

当我尝试使用深层链接而不是调用下面的函数时,上面的函数不再存在。

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

}

在这种情况下,此功能的相关性是什么?

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return true
    }

是否有人为 Xcode 11 开发过深度链接或遇到过类似的决策问题?你能指导我解决这个问题吗?

方法 scene(_ scene:, openURLContexts URLContexts:) 在 iOS >= 13 上被调用。

旧方法 application(_ app:, open url:, options:) 在 iOS < 13 时被调用。

因此,除非您只针对 iOS 13,否则您必须在两种方法中处理 URL。

So, unless you are only targetting iOS 13, you have to handle the URL in both methods.

这是不正确的。

在任何给定时刻,系统只考虑 AppDelegate.openUrl(...)SceneDelegate.openURLContexts(...) 之间的一个或另一个调用。

何时使用哪个?

最短答案:只要 SceneDelegate 被正确配置(通过将场景引用添加到 plist),SceneDelegate 的方法将被调用,同时完全忽略(即使你已经实现)AppDelegate的方法。 否则,将调用 AppDelegate 方法。

因此,ios12 运行时可以调用 SceneDelegate 方法,就像 ios13 可以调用 AppDelegate 方法一样。 这提供了向前和向后兼容性。 没有人会希望 App Store 中以前运行的应用程序突然停止在 iOS 13 设备上运行。