从启动Safari浏览器应用或应用商店? [英] Launching app OR app store from Safari?

查看:829
本文介绍了从启动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.

推荐答案

这是不可能的检查程序是从网页上安装。你可以通过检查做了其他的应用程序内,如果你的URL方案可以使用的UIApplication的-canOpenURL打开:方法,但没有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>

这code将设置如果超时结束,将调用该函数open_appstore的链接超时。由于您的链接指向应用程序的自定义网址,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.

9 iOS版增加了一个非常好的功能,让您的应用程序打开一个HTTP / S网址:<一href=\"https://developer.apple.com/library/$p$prelease/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-DontLinkElementID_2\">Universal链接

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

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

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