h5页面唤起app
const appDownload = () => { // 分享- 唤起 - 下载
function failed() {
window.location = '应用商店的scheme '
}
function transfer(cb) {
window.location.href = '自家产品的scheme,需要与客户端同事定义'
const initialTime = new Date();
let counter = 0;
let waitTime = 0;
const checkOpen = setInterval(() => {
counter++;
waitTime = new Date() - initialTime;
if (waitTime > 5000) {
clearInterval(checkOpen);
cb();
}
if (counter < 1000) { return; }
const hide = document.hidden || document.webkitHidden;
if (!hide) {
cb(); // 唤端失败的回调函数
}
}, 20);
document.addEventListener('visibilitychange', () => {
const isHidden = document.hidden;
if (isHidden) {
clearInterval(checkOpen);
}
});
}
transfer(failed)
}