使用 iOS 9 个通用链接从 Safari 打开应用程序

Opening apps from Safari with iOS 9 Universal Links

在这种情况下:

  1. Twitter 的官方应用在 iOS 9
  2. 上注册处理 twitter.com 个带有通用链接的 URL
  3. 用户从 Safari 启动并安装了 Twitter 的官方应用程序
  4. 用户点击 link Twitter 声明的 URL 之一

会发生什么?它是留在 Safari 中还是切换到 Twitter 的应用程序?

直接来自Apples Website

Use Universal Links to Enable Your App to Handle Links to Your Website

重点放在你的网站上。此功能结合使用了许多东西,其中之一是共享 Web 凭据。总结如下:

Accessing shared web credentials requires permission from the app, the website, and the user.

为了实现访问,必须创建关联:

Add an apple-app-site-association file to your website. This file must include application identifiers for all the apps with which the site wants to share credentials, and it must be properly signed.

所以简而言之,是的,但也不是。它必须得到所有 agencies/parties(网站和应用程序,就像切换一样)的支持。在您的情况下,如果 Twitter 包含通用链接的正确证书(以及 Apple 包含的权利),那么它会像它已经做的那样重定向它们。

具体回答您的问题,该技术本身可以通过将用户直接发送到有问题的应用程序而不是 http通过向您自己的应用程序(com.apple.developer.associated-域)添加特定权利来调用,即使我理解您的意思。不适用于 Safari

Does it stay within Safari or switch to Twitter's app?

留在 Safari 中。


更新:一种解决方法是拥有第二个子域,您也可以将其用于通用链接。与 Twitter 示例保持一致,如果 Twitter 使用 ul.t.co 作为链接,那么 twitter.com 上点击 ul.t.co 的用户将被带入 Twitter 应用程序. Branch 的用户受益于这个 "feature" 的通用链接。


这似乎是通用链接的固有限制。如果有人解决了这个问题,我很想听听解决方案。

请注意,在 iOS 9 上仍然可以在浏览器中触发 URI 方案——我们在我的公司 Branch 这样做。您需要注意的是,您不能像在 iOS 8 及以下版本中那样在 iframe 中触发 URI 方案。

所以我建议检查 navigator.agent 和:

  1. 如果它是 iOS 9 如果是这样设置 window.location = 'twitter://'; 如果您想尝试打开 Twitter 应用程序。如果用户没有安装 Twitter,他们将看到一条错误消息。

  2. 如果它是 iOS 8 或更低版本,您仍然可以在 iframe 中触发 URI 方案,如果未安装应用程序,用户将不会看到错误消息。

留在萨法里。

根据我的经验,当从其他应用程序(iMessage、邮件、Slack 等)中单击 link 以及从 safary 中的 google 搜索结果中单击时,应用程序会打开(如果结果 links 到 applinks-page)

Does it stay within Safari or switch to Twitter's app?

切换到 Twitter 应用程序(使用 Twitter 应用程序 v6.39 在 iOS 9.1 上测试),除非您已将其关闭(请参阅 st.derrick on Sep 24, 2015 in 的评论)。

它在官方 Twitter 应用程序中打开 link。

来自Apple's docs

Universal links let iOS 9 users open your app when they tap links to your website within WKWebView and UIWebView views and Safari pages, in addition to links that result in a call to openURL:, such as those that occur in Mail, Messages, and other apps.

For users who are running versions of iOS earlier than 9.0, tapping a universal link to your website opens the link in Safari.