iOS使用Universal Links唤醒App

Universal Links 是一种在 iOS 和 iPadOS 中打开应用程序的技术,它允许用户在从应用程序内部或网页中单击链接时直接在应用程序内打开相应的内容。这是通过配置一个应用程序的“associated domains”特性来实现的。

使用 Universal Links 的优势在于,它们可以提供更好的用户体验,因为它们直接在应用程序内打开链接,而不是像scheme(例如: myapp://dosomething)是在Safari中打开。

当用户在没有安装响应应用的情况下打开schema,会提示未知应用的弹窗; 但 Universal Links 不会,它依然是可以在没有安装应用的情况下正常使用Html5页面(前提是企业愿意并且有Html5版本)。

1. 勾选Identifiers详情里面的Associated Domains

打开Apple Developer里面的Identifiers列表, 找到对应的应用id,进入详情之后如下图,勾选Associated Domains。

Associated Domains

2. 配置xcode工程

在XCode Targets里面选择应用,在Signing & Capabilities标签页下面的Associated Domains添加一个值为applinks:help.wechat.com

如果没有看到Associated Domains,就需要点击右上角的“+”号按钮进行添加。

xcode-info

xcode-info

配置托管域名

我们以https://help.wechat.com/app/ 可以唤醒微信的效果为例子。

open-wechat

首先需要创建一个apple-app-site-association的文件,内容大概如下:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "[teamID].[bundleID]", // 例如:"8H3NQF6GGQ.com.tencent.xin"。
        "paths": [ "/app/*"] 
      }
    ]
  }
}

然后将这个apple-app-site-association文件上传到https://help.wechat.com/根目录下面,确保https://help.wechat.com/apple-app-site-association访问到上面的文件内容。

验证Associated Domains是否生效

首先需要将增加过Associated Domains的应用安装到手机里面,然后使用浏览器打开https://help.wechat.com/app,就能看到之前的那张图

open-wechat