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

我们有一个应用程序,让我们调用它: xyz_app我有一个自定义的URLscheme的formsxyz_app://

我们正在向用户发送电子邮件。

当他点击链接时,他会去应用程序,如果应用程序没有安装,我们的移动网站。

所以从电子邮件中的链接,我如何确保如果没有安装该应用程序,该链接应该将用户发送到移动网站?

只有当应用程序安装在iDevice上时,URLscheme才能直接工作。 如果没有安装,那么它会抛出一个错误。

1)要实现这个function,你将不得不通过你的电子邮件链接把用户redirect到一个能够检测到应用是否被安装的网页。 像这样的www.yourwebsite / detectapp

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; }