我的问题是关于 iOS9 的!
我有一个 HTML
着陆页,如果安装了应用程序,我会尝试通过 URL 方案将用户重定向到到我的应用程序,或者重定向到 Appstore否则。
我的代码是:
document.addEventListener("DOMContentLoaded", function(event) {
var body = document.getElementsByTagName('body')[0];
body.onclick = function () {
openApp();
};
});
var timeout;
function preventPopup() {
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide', preventPopup);
}
function openApp(appInstanceId, platform) {
window.addEventListener('pagehide', preventPopup);
document.addEventListener('pagehide', preventPopup);
// create iframe
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.setAttribute("style", "display:none;");
iframe.src = 'myscheme://launch?var=val';
var timeoutTime = 1000;
timeout = setTimeout(function () {
document.location = 'https://itunes.apple.com/app/my-app';
}, timeoutTime);
}
问题是 iframe
技巧在 Safari
iOS9
中不起作用。
知道为什么吗?
我的 iframe
技巧基于 this回答。
最佳答案
iframe 技巧不再有效——我猜 Apple 知道它会鼓励更多开发人员更快地实现通用链接。
您仍然可以设置 window.location='your-uri-scheme://';
并在 500 毫秒后回退到 App Store。如果你采用这种方法,弹出窗口之间会有一个“舞蹈”,就像我们在 Branch 所做的那样(如果通用链接不起作用,我们会做为后备)。
window.location = 'your-uri-scheme://'; // will result in error message if app not installed
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
我希望我能为您提供更好的答案。 iOS 9 肯定更受限制。
要了解通用链接需要什么的有用概述,请查看我的回答 here 或 read this tutorial
关于javascript - iOS9:如果可能,尝试通过方案打开应用程序,否则重定向到应用程序商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689483/