尝试打开未安装的本机应用程序时如何防止iOS safari警报? [英] how to prevent iOS safari alert when trying to open non-installed native app?
问题描述
我一直在寻找一种从浏览器打开原生iOS应用的方法。
我在这里找到了一个不错的解决方案:是否可以为YouTube应用程序(如YouTube和地图)注册基于http +域的URL方案?
I've been looking for a way to open a native iOS app from the browser. I found a decent solution here: Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?
当您安装了应用程序时,此解决方案非常有用。但是当用户没有安装此应用程序时 - safari将触发一条错误消息,指出Safari无法打开该页面,因为该地址无效。
This solution works great when you have the app installed. but when a user doesn't have this app installed - safari fires an error message which says "Safari cannot open the page because the address is invalid."
是否有防止这种行为的方法,而不是提示用户下载应用程序?
Is there a way to prevent this behaviour and instead to prompt the user to download the app?
推荐答案
这是一个适合我的解决方案:
Here is a solution that works for me:
var timeout;
function preventPopup() {
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide', preventPopup);
}
function openApp() {
$('<iframe />')
.attr('src', appurl)
.attr('style', 'display:none;')
.appendTo('body');
timeout = setTimeout(function() {
document.location = appstore;
}, 500);
window.addEventListener('pagehide', preventPopup);
}
这篇关于尝试打开未安装的本机应用程序时如何防止iOS safari警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!