分享

[iOS] Check if app in iOS/Android, open link in app

 openlog 2015-04-11

需求如下:在android/ios device里,点击LINK (不管是在MAIL APP还是在WEB BROWSER里),如果你的APP有安装在DEVICE上,就打开APP,如果没安装就打开APP STORE并进入该APP的安装页面。

 

有2种途径:

途径1. custom url scheme.  (最大的limitation: gmail对于custom scheme的link (e.g. fb://profile) 会filter link URL,即只显示text而不显示成link)

ref link: http:///2013/09/20/url-schemes-for-ios-and-android-2/

src: https://gist.github.com/FokkeZB/6635236

中文参考链接:

http://www.cnblogs.com/iamjiuye/p/3362978.html

http://blog.csdn.net/hundsong/article/details/6623500 

 

例如 fb://profile (example link: http:///test/fb.html)

前提是你的android/ios app都有处理custom url scheme的设置

IOS (v7.1)

如果你的iphone装了facebook app,那么当你点这个link就会启动app。

如果没有装facebook app,如果这个link是来自mail app,那么在mail app里click it没反应,如果这个link来自safari browser app,点该link就会popup error window "safari cannot open the page because the address is invalid."

因此如果要使用这个方案,你需要先把链接link to 服务器端的一个web page, 由该web page使用javascriptjavascript来先check是否install app,具体方案是set window.location为fb://profile,并设置timeout function:如果window.location不成功,则表示没有装app,应该set windows.location as app store url (ref link: http:///2013/09/20/url-schemes-for-ios-and-android-2/)

 

Android (test environment: v4.2.1)

如果android device安装了app,那么你在web browser点该link (fb://profile),就会用launch该app,如果有多个app都能处理该custom scheme,就会问你使用哪个app来打开。当你选择了“永远都用这个app"打开之后,那么再也不能用其他APP来处理该custom scheme。(除非删除app,或者有其他方法,没研究)

如果android device没有安装APP,如果在web browser里点该link (fb://profile),显示error "webpage not available" . 而且用JAVASCRIPT是无法检测app是否有安装。(REF LINK)

 而http://blog.csdn.net/hundsong/article/details/6623500提供了另外一个for android的方法:即对APP设置会处理某个HTTP URL(例如http://xxxx/check.php),如果device没有安装app,就会在web browser里直接打开该URL,而如果安装了该app,就会popup问你用什么来打开该url,那么同样会有上面提到的“永远使用某个app来处理该url”的问题。最致命的缺点是这个HTTP URL必须是fix的,无法带dynamic parameter。


不过http:///2013/09/20/url-schemes-for-ios-and-android-2/还是给出了solution for android:即直接使用"intent://" scheme (测试时可以直接使用href="intent://XXXXXXX")

这是源自https://developer./multidevice/android/intents,不过有限制!!必须是chrome browser version 25 或更加新的版本,不知道mail app是否支持,而且第三方的browser (e.g. UC) 不支持 (http://blog.csdn.net/geekpark/article/details/16118457)。

"intent://"的例子

1.百度云app的intent

<a href="intent://scan/#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end">baidu cloud</a>

这样不管你的device有没有装百度云app,点link都会转到google play的百度云app页面

<a href="intent://map/geocoder?location=39.990912172420714,116.32715863448607#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end">baidu cloud</a>

如果你的device没有装百度云app,点link都会转到google play的百度云app页面,如果安装了,就会启动app并显示北京地图


2. QR code app的intent

<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end">qr code app</a>

这样不管你的device有没有装 qr code app,点link都会转到google play的 qr code app页面


3. http的intent

<a href="intent://www.google.com#Intent;scheme=http;action=android.intent.action.VIEW;end">google</a>

如果你的device安装了chrome,就会提示你用default browser打开还是用chrome打开


注意:如果直接在android default mail app里直接显示custom scheme link (e.g. fb://profile     intent://xxxx),不管device是否有装app,会显示error "web page not availble",而且link的scheme变成email://,因此不要奢望直接在邮件里提供custom scheme link,而应该是提供一条http link,点它在web browser里打开,然后由web page的javascript来redirect to custom scheme url



途径2. 使用app banner in web page

iOS 

promotion app banner in web page

Android 

android并没有提供类似于ios的app banner,不过有一个jquery "smart banner" for android,不过这使得你的web page load变慢,因为要用到jquery

demo: http://jasny./jquery.smartbanner/   该demo support Android, 但在iOS里则显示2个banner: jquery banner和native smart banner.


ref link about smart app banner: https://www./content/application-development-blog/-/blogs/smart-app-banners-for-ios-and-android


 

http:///2013/08/26/url-schemes-for-ios-and-android-1/


custom url scheme

https:///jasonkneen/titanium-and-url-schemes



 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多