為了下次開(kāi)發(fā)涉及通用連接Universal link 的分享和支付等功能的時(shí)候少走彎路 對(duì)這個(gè)點(diǎn)進(jìn)行下資料整理,僅供參考
1.登錄蘋(píng)果開(kāi)發(fā)者賬號(hào)https://developer.apple.com/account/resources/identifiers/bundleId/edit/U2WP8G7T54 創(chuàng)建?identifiers
2.開(kāi)通Associated Domains

3.制作相關(guān)證書(shū)配置文件

4.創(chuàng)建純文本不帶后綴名的文件apple-app-site-association
如果要支持QQ分享配置如下
{
? ? "applinks": {
? ? ? ? "apps": [],
? ? ? ? "details": [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "appID": "teamid.bundleid",
? ? ? ? ? ? ? ? "paths": [ "*","/qq_conn/appid/*" ]
? ? ? ? ? ? }
? ? ? ? ]
? ? }
}
微信支付和分享
{
? ? "applinks": {
? ? ? ? "apps": [],
? ? ? ? "details": [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "appID": "teamid.bundleid",
? ? ? ? ? ? ? ? "paths": [ "*","/path/*" ]
? ? ? ? ? ? }
? ? ? ? ]
? ? }
}
5.將apple-app-site-association文件上傳至HTTPS服務(wù)器根目錄或者.well-known這個(gè)子目錄下。
4.下載安裝配置的證書(shū)文件 并在xcode工程中做相關(guān)配置

此處要確保:
使用https://domain.com/apple-app-site-association或者https://domain.com/.well-known/apple-app-site-association能夠訪問(wèn)到(能夠下載或者返回文件內(nèi)容即可)。這里的域名,就是2中配置xcode的Associated Domains時(shí)候提到的域名。
也可以使用蘋(píng)果的驗(yàn)證網(wǎng)站來(lái)驗(yàn)證文件是否能夠被訪問(wèn)到。若應(yīng)用未上線,可能出現(xiàn)如下結(jié)果:

特別注意:微信SDK中Universal links的使用參照微信sdk介入指引即可完成介入。但是如果完全按照該指引操作,可能會(huì)出現(xiàn)分享的時(shí)候,進(jìn)行二次跳轉(zhuǎn)的異常,具體表現(xiàn)就是:拉起微信后進(jìn)行授權(quán),然后立刻返回App,然后再次調(diào)起微信,這是由于通用鏈接授權(quán)失敗,第二次降級(jí)為URLScheme方式啟動(dòng)微信。
如果保證了Universal links的配置正確,并且嚴(yán)格按照微信的接入文檔執(zhí)行操作,為什么通用鏈接授權(quán)還會(huì)失敗呢?
2.建議Universal links 配置path 例如/app/*,避免全域名命中Universal links?
例如apple-app-site-association文件配置為{
? ? "applinks": {
? ? ? ? "apps": [],
? ? ? ? "details": [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "appID": "teamid.bundleid",
? ? ? ? ? ? ? ? "paths": [ "*","/testapp/*" ]
? ? ? ? ? ? }
? ? ? ? ]
? ? }
}
該文件上傳的Https域名服務(wù)器 為 https://www.test.com/
那么 微信后臺(tái)需要填寫(xiě)配置的通用連接Universal link 為https://www.test.com/testapp/
App中調(diào)用微信openSDK的+(BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink方法的通用鏈接參數(shù)也一定要帶路徑即https://www.test.com/testapp/,保持一致,單純的域名就會(huì)導(dǎo)致二次降級(jí)啟動(dòng)。
Xcode ?中配置如下圖

驗(yàn)證通用連接是否配置正確的方法:
1)將應(yīng)用打包或者真機(jī)調(diào)試安裝到手機(jī)上,json格式的文件是app第一次安裝,它會(huì)從https://domain.com/apple-app-site-association下載這個(gè)文件。
2)需要測(cè)試該功能的時(shí)候,只需要在備忘錄輸入App能識(shí)別的鏈接https://www.test.com/testapp/,然后直接點(diǎn)擊或是長(zhǎng)按就可以了,直接點(diǎn)的效果是跳轉(zhuǎn)到你的App,長(zhǎng)按的效果是彈出的菜單中第二項(xiàng)是“在'XXX應(yīng)用'中打開(kāi)”,這也代表著成功。
3)如果未安裝應(yīng)用或者安裝了應(yīng)用由于網(wǎng)絡(luò)的原因沒(méi)有正確下載到apple-app-site-association文件則不會(huì)出現(xiàn)XXX應(yīng)用中打開(kāi) ,這時(shí)候需要安裝應(yīng)用,切換網(wǎng)絡(luò)重試。
附圖備忘錄中長(zhǎng)按可以看到

Safari瀏覽器中輸入通用連接后下拉應(yīng)該能看到 APP中打開(kāi) 點(diǎn)擊點(diǎn)開(kāi)按鈕可以打開(kāi)應(yīng)用

備忘錄中復(fù)制通用連接https://www.test.com/testapp/ ?點(diǎn)擊連接 可以正常直接打開(kāi)APP
參考一下資料:
http://www.itdecent.cn/p/c9c09992a6fe?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
http://www.itdecent.cn/p/00dace48a53b
http://www.itdecent.cn/p/ab50bdaec65d通用連接配置文章
https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html 微信配置universal link