如何通过Safari中的网页安装应用程序? [英] How to open an app if installed through a webpage in Safari?

查看:826
本文介绍了如何通过Safari中的网页安装应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,可以称之为: xyz_app ,我有一个自定义URL方案,格式为 xyz_app://

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



当他点击链接时,他是想去应用程序,并在应用程序未安装,我们的手机网站。



所以从电子邮件的链接,我怎么确定如果应用程序未安装,该链接应将用户发送至移动网站? 解决方案

只有当应用程序安装在iDevice上时。如果没有安装,那么它会引发错误。
$ b $ 1要实现这个功能,你必须将用户重定向到一个网页,该网页将检测是否安装了应用程序,从你的邮件链接。就像这样www.yourwebsite / detectapp


2)你的detectapp页面将有一个javascript-

  var appstoreFail =www.your_redirect_website.com; 

//检查设备是iOS
var iOS = /(iPad|iPhone|iPod)/.test(navigator.userAgent);
var appUrlScheme =xyz_app://;

if(iOS){
//如果未安装应用程序,脚本将等待2秒钟并重定向到网页。
var loadedAt = + new Date;
setTimeout(function(){
if(+ new Date - loadedAt< 2000)
window.location = appstoreFail;
},25);
//尝试使用URL模式启动应用程序
window.open(appUrlScheme,_self);
} else {
//启动网站
window.location = appstoreFail;
}


We have an app, lets call it: xyz_app for which I have a custom URL scheme in form of xyz_app://.

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. 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. Something like this www.yourwebsite/detectapp

2) Your detectapp page will have a 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;
}

这篇关于如何通过Safari中的网页安装应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆