如果不满足特定条件,你怎么能忽略通用 link?

How can you ignore a universal link if a certain condition is not met?

我们目前支持通用链接的通配符。所以我的应用程序links 看起来像:applinks:*.company.com.

假设我只想处理 link 如果它是 https://company.com/?query1=abc

假设我点击 link 即 https://company.com/?query1=123

由于不满足条件,我想忽略此 link 并阻止我的 iOS 应用响应它。这可能吗?

我以为我可以在 continue:restorationHandler 中 return false 但这不会阻止 iOS 应用程序打开。

application(_:continue:restorationHandler:) 返回 false 不会导致 URL 传回 Safari(如您所见)。文档指出:

If you don't implement this method or if your implementation returns false, iOS tries to create a document for your app to open using a URL

因此返回 false 只会导致 iOS 尝试以不同的方式启动您的应用程序。

您可以调用 open(_:options:completionHandler:) 并传递您收到的 URL。然后 URL 将在 Safari 中打开; iOS 不会向您的应用传递您的应用自行打开的通用 link,因为这可能会造成无限循环。