gpt4 book ai didi

ios - 如何不以编程方式处理某些通用链接?

转载 作者:行者123 更新时间:2023-11-29 05:25:33 26 4
gpt4 key购买 nike

我的 iOS 应用程序处理 universal links将 Safari 用户重定向到我的应用程序。到目前为止,一切都运行良好,如果用户点击从 Google 到我的网站的链接,我的应用程序将打开,而不是像这样打开我的网站:

from safari https://my-web-site.com -> my-app

但是我的应用程序没有实现我的网站所实现的某些功能,因此我想以编程方式拒绝某些 URL,并让我的用户使用 Safari,而不是在我的应用程序中重定向他,如下所示:

from safari https://my-web-site.com -> my-app

from safari https://my-web-site.com?reject -> safari

根据Apple documentation这应该是可能的:

It’s important to understand that if your app uses openURL: to open a universal link to your website, the link does not open in your app. In this scenario, iOS recognizes that the call originates from your app and therefore should not be handled as a universal link by your app.

不幸的是,这不是附加的内容,我的用户没有停留在 safari 中,而是被重定向到我的应用程序一小会儿,然后再次重定向到 safari,如下所示:

from safari https://my-web-site.com?reject -> my-app (briefly) -> safari

这是我的 AppDelegate.swift 代码:

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

let params = urlComponents.queryItems ?? []

if params.contains(where: { $0.name == "reject" }) {
// This line should prevent the app from opening according to Apple's documentation
application.open(url)
return false
} else {
return true
}
}

那么有人知道如何按照 Apple 文档中描述的方式拒绝通用链接吗?

注意:拒绝通用链接需要由应用程序根据本地存储的数据以编程方式完成。因此在 apple-app-site-association 中添加路径异常在我的情况下,文件不是一个选项:

{
"applinks": {
"apps": [],
"details": [
{
"appID": "XXXXXXXXX.com.my-app",
"paths": [
"*",
"NOT /reject"
]
}
]
}
}

最佳答案

如果在路径数组中为条目添加前缀“NOT”,则可以显式阻止匹配。所以在你的例子中你可以做类似的事情

["NOT /settings/*", "NOT /activity/*", "/*"] 

这将阻止带有 /settings/activity 前缀的路径,然后匹配其他所有内容。


Reference

关于ios - 如何不以编程方式处理某些通用链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com