从 Safari 启动应用程序或应用程序商店? [英] Launching app OR app store from Safari?

查看:57
本文介绍了从 Safari 启动应用程序或应用程序商店?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何从 safari 启动应用程序,但是否可以在启动前检查应用程序是否已安装?如果 iPhone 上当前未安装该应用,我正在考虑启动该应用商店.

I already know how to launch an app from safari, but is it possible to check if the app is installed before launching? I'm thinking to launch the app store if the app isn't currently installed on the iPhone.

推荐答案

无法检查是否从网页安装了应用程序.您可以通过检查是否可以使用 UIApplication 的 -canOpenURL: 方法打开您的 url 方案来在其他应用程序中执行此操作,但没有与此等效的 javascript.

It's not possible to check if app is installed from a web page. You could do it inside an other app by checking if your url scheme can be opened using UIApplication's -canOpenURL: method, but there is no javascript equivalent to this.

但是,您可以使用以下解决方法:

However, you can use the following workaround:

<script language="javascript">
    function open_appstore() {
        window.location='http://itunes.com/';
    }

    function try_to_open_app() {
        setTimeout('open_appstore()', 300);
    }
</script>

<a onClick="javascript:try_to_open_app();" href="yourappurl:">App name</a>

此代码将在链接上设置超时,如果超时结束,该链接将调用 open_appstore 函数.由于您的链接指向应用的自定义 url,Safari 将尝试打开该链接,如果可以,它将打开应用并停止计时器,因此不会打开 AppStore 链接.

This code will set a timeout on the link that will call the open_appstore function if this timeout ends. Since your link is pointed at the app's custom url, Safari will try to open that link and if it can, it will open the app and stop the timer, so AppStore link will not be opened.

如果应用程序链接无法打开,当计时器用完时,它会显示一个错误弹出窗口,说它无法打开页面(无法摆脱),但它会立即转到 AppStore 并关闭那个错误.

If the app link can't be opened, when timer runs out it will display an error popup saying it can't open the page (can't get rid of that), but it will immediately go to AppStore and dismiss that error.

iOS 9 添加了一个非常棒的功能,可以让您的应用打开 http/s 网址:通用链接

iOS 9 adds a really nice feature that lets your app open a http/s url: Universal Links

iOS 10 中,当您点击链接并安装应用时,会弹出一个提示在 [应用名称] 中打开".如果用户没有在给定的 timeout 内点击Open",则此解决方案将使用回退.由于 300 毫秒太短,无法点击任何内容,此解决方案在 iOS 10 上总是失败.

In iOS 10 there is a popup saying "Open in [App Name]" when you tap the link and the app is installed. If the user does not tap on "Open" in the given timeout, this solution will use the fallback. As 300ms is too short to tap anything, this solution always fails on iOS 10.

这篇关于从 Safari 启动应用程序或应用程序商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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