app分享后点击进入
需求:APP中分享出去的文章需要在其它应用打开后,通过右上角的打开还能跳转到相对应的APP详情页面
用web打开自己app的协议,app未安装时跳转到appstore
在ios9中打开app时强制提示“Safari打不开该网页,因为网址无效”
想问有没有什么方案,既能在app已安装时打开app,又能在app未安装时跳过上面的提示直接setTimeout到appstore
前提:知道自己APP对应的打开协议(scheme url),比如:贴吧APP:com.baidu.tieba://,微信的:weixin://
ios:
Safari启动自定义的URL Schemes APP
android:
我们的是android:scheme="sxcoal.mt" android:host="com"
因此分享时候 使用的为sxcoal.mt://com/参数(模块+分类)
分享的流程:
1.浏览APP中看到某一篇喜欢的文章,分享单篇文章到通讯软件(微信、qq、微博等)
2.其它好友看到分享的信息,打开分享的内容,有立即打开的字样
3.点击立即打开,可能有一些软件支持直接跳转,但是大部分是不允许在此应用中打开其它应用的,因此做了一个过渡页
4.根据提示进行操作
注意:这个地方有一个特殊的逻辑
首先进入页面会判断是否有APP,如果有APP会提示你是否打开APP
如果取消了,下面有立即下载按钮,也是相应的逻辑
打开之后,APP会根据我返回的参数,跳转到某一页的详情页
通过浏览器打开页面的提示以及点击按钮的逻辑,其它都是做一个铺垫进行数据的传输以及过度
代码:
var iphoneSchema = 'fenwei.meitan://html/<?=$apptype?>@<?=$id?>'; //iOS 9及以上版本 var universalLink = 'https://app.xxxxxx.com/share/project?cid=39783&cover=http://file.xxxxxx.com/eImg/uimages/20170901/1504260781459851.jpg'; //https://app.xxxxxx.com/share/article?cid=39783&cover=http://file.xxxxxx.com/eImg/uimages/20170901/1504260781459851.jpg //Android 打开京东 var androidSchema = 'fenwei.meitan://html/<?=$apptype?>@<?=$id?>'; var downUrl = '<?=$url?>';//下载连接 var isIphone = navigator.userAgent.match(/(iPhone|iPod|iPad);?/i); var isAndroid = navigator.userAgent.match(/android/i); var isWeixin = function(){ //判断是否是微信 var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } }; $(document).ready(function(){ if (isAndroid) { var ifr = document.createElement('iframe'); ifr.src = androidSchema; ifr.style.display = 'none'; document.body.appendChild(ifr); setTimeout(function () { document.body.removeChild(ifr); }, 3000); } else if (isIphone) { var ifr = document.createElement('iframe'); ifr.src = iphoneSchema; ifr.style.display = 'none'; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000); } }); function open_app() { // alert("android"+androidSchema); // alert("ios"+iphoneSchema); if (isAndroid) { //alert("安卓"); $('#open_app').attr('href', downUrl); var ifr = document.createElement('iframe'); ifr.src = androidSchema; ifr.style.display = 'none'; document.body.appendChild(ifr); setTimeout(function () { document.body.removeChild(ifr); $('#open_app').attr('href', downUrl); }, 3000); } else if (isIphone) { /*window.location.href = iphoneSchema; setTimeout(function () { window.location.href = downUrl; }, 3000);*/ var ifr = document.createElement('iframe'); ifr.src = iphoneSchema; ifr.style.display = 'none'; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000); return false; } else { //非iOS、Android 手机, 隐藏打开文章按钮 } } |