安卓 | IOS系統 applinks 聲明與app的關聯文件
安卓 https://域名/.well-known/assetlinks.json
IOS https://域名/.well-known/apple-app-site-association
${uri} 參數:例 name=打開app&age=23
xx.xx.xx 表示安卓包名稱 || scheme名稱
打開ios app方式:
就一種 https://applinks綁定的域名${uri}
打開安卓app方式:
* intent://你的域名${uri}#Intent;scheme=https;end 這種方式如果沒有安裝app會訪問https://你的域名${uri}
* xx.xx.xx://xx${uri} 華為手機基本上都支持這種打開方式
* intent://xx${uri}#Intent;scheme=xx.xx.xx;end 測試有限,只要是Oppo手機就用這種方式打開app
* 配置applinks 僅支持6.0以上系統,如何配置叫上你們的安卓小哥哥|小姐姐《進行深入》的《探討》
```
/**
* 打開app
* @param uri
*/
export function OpenApp(uri: string) {
if (Ios) { // 檢測是否為ios
window.location.href = `https://xxxx.com/index.html${uri}`;
return;
}
let isOpenTime: boolean = false; // 是否創建定時任務
let url: string = `intent://域名/index.html${uri}#Intent;scheme=https;end`;
if (Huawei || Huawei_LLD) {
url =`xx.xx.xx://xx${uri}`; // 所有安卓手機默認使用該地址
isOpenTime = true;
}
if (Oppo) {
url = `intent://xx${uri}#Intent;scheme=xx.xx.xx;end`;
isOpenTime = true;
}
let checkTimeout: any = ''; // 檢測是否已經離開了當前頁面
document.addEventListener("visibilitychange", function(){
if (document.hidden && checkTimeout !== '') { // 如果離開當前頁面,清除定時任務
clearTimeout(checkTimeout);
}
});
window.location.href = url;
if (isOpenTime) { // 做這一步的原因:有些安卓手機 提示是否進入app,如果3秒后不做任何操作執行以下操作
checkTimeout = setTimeout(() => { // 進入下載頁面 | 直接下載 根據業務需求進行開發
window.location.href = `https://xxxx.com/index.html${uri}`;
}, 3000);
}
}
```