iOS 通用链接Universal Links(更新到最新的ios13)

什么是Universal Links?

在iOS9之前,对于从各种从浏览器、Safari中唤醒APP的需求,我们通常只能使用scheme。但是这种方式需要提前判断系统中是否安装了能够响应此scheme的app。

Universal Links是iOS9推出的一项功能,你的应用如果iOS设备上已经安装了你的app可以通过传统的HTTP链接来启动APP,iOS设备上没有安装你的app来打开网页。

官方的说明文档 怎么使用Universal Links。

1.先决条件:你必须有一个域名,且这个域名需要支持https。

2.需要在开发者中心做配置:找到对应的App ID,在Application Services列表里有Associated Domains一条,把它变为Enabled就可以了。

1608265-fc8dfd8dbab131b6.png

3.打开工程配置中的Associated Domains,在其中的Domains中填入你想支持的域名,必须以applinks:为前缀。

14A804AD-F1BB-4150-B493-D283D3A25815.png

**4.创建一个内容为json格式的文件,app安装后,app从我们在项目中填入的域名请求这个文件。这个文件名必须为apple-app-site-association,没有后缀名,文件内容大概是这样子:

ios 12及其以前**

{
  "applinks": {
      "apps": [],
      "details": [
           {
             "appID": "ABCDE12345.com.example.app",
             "paths": [ "/buy/*", "NOT /help/website/*", "/help/*" ]
           }
           {
             "appID": "ABCDE12345.com.example.app2",
             "paths": [ "/buy/*", "NOT /help/website/*", "/help/*" ]
           }
       ]
   },
   "webcredentials": {
      "apps": [ "ABCDE12345.com.example.app" ]
   }
}

ios13开始变了(有点坑)

{
  "applinks": {
      "details": [
           {
             "appIDs": [ "ABCDE12345.com.example.app", "ABCDE12345.com.example.app2" ],
             "components": [
               {
                  "#": "no_universal_links",
                  "exclude": true,
                  "comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"
               },
               {
                  "/": "/buy/*",
                  "comment": "Matches any URL whose path starts with /buy/"
               },
               {
                  "/": "/help/website/*",
                  "exclude": true,
                  "comment": "Matches any URL whose path starts with /help/website/ and instructs the system not to open it as a universal link"
               }
               {
                  "/": "/help/*",
                  "?": { "articleNumber": "????" },
                  "comment": "Matches any URL whose path starts with /help/ and which has a query item with name 'articleNumber' and a value of exactly 4 characters"
               }
             ]
           }
       ]
   },
   "webcredentials": {
      "apps": [ "ABCDE12345.com.example.app" ]
   }
}

- appID:组成方式是 teamId.yourapp’s bundle identifier。如上面的 9JA89QQLNQ就是teamId。登陆开发者中心,在Account - Membership里面可以找到Team ID

-paths:设定你的app支持的路径列表,只有这些指定的路径的链接,才能被app所处理。星号的写法代表了可识别域名下所有链接

5. 上传该文件到你的域名所对应的根目录或者.well-known目录下,这是为了苹果能获取到你上传的文件。上传完后,自己先访问一下,看看是否能够获取到,当你在浏览器中输入这个文件链接后,应该是直接下载apple-app-site-association文件。

在safari中输入一下两个链接能下载到上述的json文件

(https://你的域名/.well-known/apple-app-site-association)

(https://你的域名/apple-app-site-association)

6.如果能够下载成功了,为了能够分享到微信和QQ,你还需要到微信开发者中心中和QQ互联中填写Universal Links并且需要验证

#7.在此强调一个重要的信息,第3步中的域名一旦填写,还有json文件一旦填写升级app既生效,如果想修改json中的信息,只能等app下次升级才能起作用(或者卸载app重装)(大坑,大坑)。一旦你的rul链接中有第3步中的域名,那么他们会微信和safari中直接调起app,所以,第3步中的域名要使用平时你们的分享以及业务不用到的域名。
相关文档

*   The `apple-app-site-association` file is cached *once* when the app is first installed.
*   If this initial scrape fails, in almost all situations it will not be reattempted. The only exception to this is if the initial return is a 5xx error, in which case a limited number of retries may occur. This is not well-documented, and is not covered in Universal Links documentation at all. You can find a mention in the [Shared Web Credentials docs](https://developer.apple.com/reference/security/1654440-shared_web_credentials).
*   The file is *not* checked at all when a Universal Link is opened. This is why you are able to get Universal Links behavior in airplane mode.
*   The file does not expire. Once it is cached, it sticks permanently for as long as the app is installed.
*   The file will be re-checked when installing an app update.
*   The file must be accessible via a valid SSL connection at either `https://example.com/apple-app-site-association` or `https://example.com/.well-known/apple-app-site-association`. If there are redirects of any kind, this will fail.
*   It is theoretically possible to MITM the request if you are able to install a new SSL certificate directly on the device in question. [Charles Proxy](https://www.charlesproxy.com) for example uses this approach for debugging. I have never seen or heard of this being exploited, and the damage would be quite limited because the domain still has to be specified inside the app itself.

参考文档1
参考文档2

你可能感兴趣的:(iOS 通用链接Universal Links(更新到最新的ios13))