Universal Links 相關文檔
先上效果:
工作原理
1、App第一次啟動時,或App更新后第一次啟動時,會通過Associated Domains里取的域名,通過GET請求訪問apple-app-site-association的文件
2、訪問到到apple-app-site-association文件,統一注冊到系統
3、任意Webview(包括第三方應用內的Webview)發起跳轉(必須要跨域跳轉),如果命中通過apple-app-site-association注冊的通用鏈接,就會找到AppID
4、如果下載安裝過該App則會打開App 觸發 Universal Link Delegate事件,如果沒安裝,則繼續跳轉url
應用場景
1、微信?WechatOpenSDK_NoPay 1.8.6.1版本初始化需要配置universalLink
/*! @brief WXApi的成員函數,向微信終端程序注冊第三方應用。?
* 需要在每次啟動第三方應用程序時調用。
* @attention 請保證在主線程中調用此函數?
* @param appid 微信開發者ID
* @param universalLink 微信開發者Universal Link
* @return 成功返回YES,失敗返回NO。?
*/
+ (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink;
2、類似淘寶、小紅書詳情自動跳轉到原生App,若未安裝,可以顯示原鏈接內容
開始配置
1、配置developer.apple.com?后臺 Certificates, Identifiers & Profiles ,在Identifiers 中 找到對應的 Identifiers,進行配置
2、在工程中,配置Domains,配置Domains,需要?applinks: 開頭,結構為:applinks:<domains>, 例如:applinks:www.baidu.com
3、服務端配置apple-app-site-association文件,通過瀏覽器能夠直接訪問:https://<domains>/.well-known/apple-app-site-association 或者?https://<domains>/apple-app-site-association能夠直接訪問到配置文件
apple-app-site-association 模板:
{
?"applinks": {
?????"apps": [],
?????"details": [ {
?????????????"appID": "9JA89QQLNQ.com.apple.wwdc",? ? // TeamID.BoundleID
?????????????"paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]? ? // 正則匹配URL域名后面的路徑
?????????}, {
?????????????"appID": "ABCD1234.com.apple.wwdc",
?????????????"paths": [ "*" ]
?????????} ]
?????}
}當safri瀏覽器訪問https://<domains>/wwdc/news/ 或?https://<domains>/videos/wwdc/2015/xxx 時,會檢測iOS設備是否安裝?9JA89QQLNQ.com.apple.wwdc 這個App,如果安裝,則會跳轉到原生應用,并保留safri頁面,如果未安裝,則停留safri頁面,并打開當前網頁。
當有多個details時,匹配規則從上到下一次匹配,匹配到后就不再往下匹配
這個步驟坑比較多,且排查困難
坑1:運維存放文件時,不能以json文件格式保存。不需要加任何擴展名
Don’t append?.json?to the?apple-app-site-association?filename.
坑2:通過瀏覽器返回時,Response Headers的Content-Type設置為:text/html,不能用text/plain。因為text/plain返回的瀏覽器會當作文本不作任何解析
坑3:必須要Https下才能正確訪問到,且文件必須在根目錄下才能訪問
最總目的是 https://<domains>/.well-known/apple-app-site-association 或 https://<domains>/apple-app-site-association 能訪問
目前我們的方案可以參考一下:
nginx 配置
? ? location /apple-app-site-association {
? ? ? ? charset UTF-8;
? ? ? ? default_type text/html;
? ? ? ? return 200?'{\"applinks\":{\"apps\":[],\"details\":[{\"appID\":\"appID.com.xxxx\",\"paths\":[\"*\", \"/*\"]}]}}'
????}
? ?
官方驗證鏈接:蘋果官方測試鏈接
配置結果說明:
1、
Error no apps associated with url
配置異常,沒有訪問到apple-app-site-association的文件
2、
Error?no apps with domain entitlements
The entitlement data used to verify deep link dual authentication is from the current released version of your app. This data may take 48 hours to update.
48小時后生效
3、
配置成功的標志