url Scheme 调用 App
// 调用 App
function callApp(schema, timeOut) {
let timer,
start = new Date().getTime();
let myPromise = new Promise((resolve, reject) => {
window.location.href = schema;
window.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
clearTimeout(timer);
resolve();
}
});
timer = setTimeout(() => {
let end = new Date().getTime();
if (end - start > timeOut + 1000) {
clearTimeout(timer);
resolve();
} else {
reject();
}
}, timeOut);
});
return myPromise;
}