简体   繁体   English

如果通过Safari中的网页安装,如何打开应用程序?

[英]How to open an app if installed through a webpage in Safari?

We have an app, lets call it: xyz_app for which I have a custom URL scheme in form of xyz_app:// . 我们有一个应用程序,我们可以调用它: xyz_app ,我有一个xyz_app://形式的自定义URL方案。

We are sending an email to the user. 我们正在向用户发送电子邮件。

when he clicks on the link, he is suppose to go to the app and in case the app is not installed, our mobile website. 当他点击链接时,他想要去应用程序,如果没有安装应用程序,我们的移动网站。

so from the Link in the email, how do I make sure that if the app is not installed, that link should send the user to the mobile website instead ? 所以从电子邮件中的链接,如何确保如果未安装该应用程序,该链接应该将用户发送到移动网站?

The URL scheme works directly only if the app is installed on the iDevice. 只有在iDevice上安装了应用程序时,URL方案才能直接运行。 If not installed then it will throw an error. 如果没有安装,则会抛出错误。

1) To implement this functionality you will have to redirect the user to a webpage that will detect if app is installed, from your email link. 1)要实现此功能,您必须从用户的电子邮件链接将用户重定向到将检测是否已安装应用程序的网页。 Something like this www.yourwebsite/detectapp 像这样的东西www.yourwebsite / detectapp

2) Your detectapp page will have a javascript- 2)您的detectapp页面将有一个javascript-

var appstoreFail = "www.your_redirect_website.com";

//Check is device is iOS
var iOS = /(iPad|iPhone|iPod)/.test(navigator.userAgent);
var appUrlScheme = "xyz_app://";

if (iOS) {
    // If the app is not installed the script will wait for 2sec and redirect to web.
    var loadedAt = +new Date;
    setTimeout(function() {
        if (+new Date - loadedAt < 2000)
            window.location = appstoreFail;
    } ,25);
    // Try launching the app using URL schemes
    window.open(appUrlScheme, "_self");
} else {
    // Launch the website
    window.location = appstoreFail;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试打开未安装的本机应用程序时如何防止 iOS Safari 警报? - how to prevent iOS safari alert when trying to open non-installed native app? 如何检查是否从Safari中的JS安装了应用程序? - How to check if an app is installed from a JS in Safari? 通过浏览器打开Android应用(如果已安装应用),否则打开playstore - Open Android app through browser if app is installed else open playstore 在 iOS 上的 Safari 中全屏打开网页 - Open webpage in fullscreen in Safari on iOS 检查是否从网页安装了应用 - Check if app is installed from webpage 如何使用JavaScript打开已安装的iOS应用? - How to open installed iOS app by Using JavaScript? 我怎么知道Safari是否已经在iPhone上安装了应用程序 - How do I know if an app is already installed on iPhone from Safari 如果在 iOS 9+ 上的 Safari 中的手机上安装了应用程序,如何从 Javascript 检查? - How to check from Javascript if an app is installed on the phone in Safari on iOS 9+? 通过iOS中的Safari在Google Chrome中打开网页 - Open webpage in Google Chrome from Safari in iOS 如果已安装,则通过深层链接打开 Android 应用程序,如果未安装,则退回到网络 - Open Android app through deep link if it's installed or fall back to web if not installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM