iOS9:尽可能尝试通过方案打开应用程序,否则重定向到应用程序商店 [英] iOS9: Try to open app via scheme if possible, or redirect to app store otherwise
问题描述
我的问题是仅限iOS9!
我有 HTML
登陆页面,我尝试通过网址方案将用户重定向到我的应用(如果已安装该应用),或者重定向到 Appstore 。
我的代码是:
document.addEventListener(DOMContentLoaded,function(event){
var body = document.getElementsByTagName('body')[0];
body.onclick = function(){
openApp();
};
});
var timeout;
函数preventPopup(){
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide',preventPopup);
}
函数openApp(appInstanceId,platform){
window.addEventListener('pagehide',preventPopup);
document.addEventListener('pagehide',preventPopup);
//创建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技巧不再适用 - 我的猜测是Apple知道它会鼓励更多开发人员更快地实施Universal Links。 / p>
您仍然可以设置 window.location ='your-uri-scheme://';
并回退到500ms后的App Store。如果采用这种方法,弹出窗口之间会有一种跳舞,就像我们在分支机构中所做的那样(如果你做的话,我们会做一个后备通用链接不起作用)。
window.location ='your-uri-scheme://'; //如果未安装app,将导致错误消息
setTimeout(function(){
//应用程序商店的链接应该转到此处 - 只有在深层链接失败时才会触发
window.location =https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8;
},500);
我希望我有更好的答案。 iOS 9肯定更受限制。
如果您想要了解Universal Link所需的内容,请查看我的答案这里或阅读本教程
My question is about iOS9 only!
I have an HTML
landing page, and I try to redirect the user to my app via URL scheme if the app is installed, or redirect to the Appstore otherwise.
My code is:
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);
}
The problem is that the iframe
trick doesn't work in Safari
iOS9
.
Any idea why?
My iframe
trick based on this answer.
The iframe trick no longer works -- my guess is that Apple knows it will encourage more developers to implement Universal Links, more quickly.
You can still set window.location='your-uri-scheme://';
and fallback to the App Store after 500ms. There is a "dance" between popups if you take this approach, as we do at Branch (we do as a fallback if Universal Links don't work).
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);
I wish I had a better answer for you. iOS 9 is definitely more limited.
For a helpful overview of what's needed for Universal Links should you go that route, check out my answer here or read this tutorial
这篇关于iOS9:尽可能尝试通过方案打开应用程序,否则重定向到应用程序商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!