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

什么是Universal Links?

在iOS9之前,對于從各種從瀏覽器、Safari中喚醒APP的需求,我們通常只能使用scheme。但是這種方式需要提前判斷系統(tǒng)中是否安裝了能夠響應此scheme的app。

Universal Links是iOS9推出的一項功能,你的應用如果iOS設備上已經(jīng)安裝了你的app可以通過傳統(tǒng)的HTTP鏈接來啟動APP,iOS設備上沒有安裝你的app來打開網(wǎng)頁。

官方的說明文檔 怎么使用Universal Links。

1.先決條件:你必須有一個域名,且這個域名需要支持https。

2.需要在開發(fā)者中心做配置:找到對應的App ID,在Application Services列表里有Associated Domains一條,把它變?yōu)镋nabled就可以了。

1608265-fc8dfd8dbab131b6.png

3.打開工程配置中的Associated Domains,在其中的Domains中填入你想支持的域名,必須以applinks:為前綴。

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

**4.創(chuàng)建一個內(nèi)容為json格式的文件,app安裝后,app從我們在項目中填入的域名請求這個文件。這個文件名必須為apple-app-site-association,沒有后綴名,文件內(nèi)容大概是這樣子:

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。登陸開發(fā)者中心,在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,你還需要到微信開發(fā)者中心中和QQ互聯(lián)中填寫Universal Links并且需要驗證

#7.在此強調(diào)一個重要的信息,第3步中的域名一旦填寫,還有json文件一旦填寫升級app既生效,如果想修改json中的信息,只能等app下次升級才能起作用(或者卸載app重裝)(大坑,大坑)。一旦你的rul鏈接中有第3步中的域名,那么他們會微信和safari中直接調(diào)起app,所以,第3步中的域名要使用平時你們的分享以及業(yè)務不用到的域名。
相關(guān)文檔

*   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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容