首页 > 解决方案 > 在 AppDelegate 中访问 Universal Link app-argument

问题描述

我正在努力在我们的网站上实施通用链接,我遇到了一个看似简单但我无法弄清楚的问题。搜索 Google 和 Stack Overflow 没有帮助,这让我相信我可能只是遗漏了一些东西。

基本上,我将以下内容添加到我的页面标题(其 URL 为“https://www.website.com/slug”)。

<meta name="apple-itunes-app" content="app-id=xxx, app-argument=https://www.website.com/1" />

请注意,该app-argumentURL 与实际页面的 URL 不同。

我已经正确设置了我的 apple-app-site-association 文件。当我尝试在我们的 iOS 应用程序中处理通用链接时,我会这样做:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard
        userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let url = userActivity.webpageURL,
        let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else
    {
        return false
    }

    // Set breakpoint here.
    return false
}

我在最后设置断点return false,当我检查时components,它包含实际页面 URL(“https://www.website.com/slug”)而不是通过传入的 URL app-argument(“https://www.website .com/id”)。

所以我的问题是:如何app-argument在我的 AppDelegate 中访问?

标签: iosswiftios-universal-links

解决方案


推荐阅读