【问题标题】:How to open an app if installed through a webpage in Safari?如果通过 Safari 中的网页安装,如何打开应用程序?
【发布时间】:2013-07-12 15:15:00
【问题描述】:

我们有一个应用程序,我们称之为:xyz_app,我有一个xyz_app:// 形式的自定义 URL 方案。

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

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

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

【问题讨论】:

    标签: javascript html ios objective-c


    【解决方案1】:

    仅当应用程序安装在 iDevice 上时,URL 方案才能直接工作。如果没有安装会报错。

    1) 要实现此功能,您必须将用户重定向到一个网页,该网页将通过您的电子邮件链接检测是否安装了应用程序。像这样 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;
    }
    

    【讨论】:

    • 好的。谢谢。我会试试这个。
    • setTimout没有直接设置为2秒有具体原因吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多