需求:在做商品分享/直播分享时,app内分享出去的链接,能够在微信、手机浏览器打开。
遇到的问题:
1,Android,当手机没有下载app时,在浏览器打开,会下载app,但是手机下载了app,除了会跳到分享的商品页,1s后还会提示下载(暂未解决,另外:Android不支持微信里跳转到app分享页)
2.ios却能在微信里-直接跳转到App分享的页面,但是手机没用下载App时,只能够加个中间页-提示用户浏览器打开。把跳转App Store的链接放到中间页就可以跳到商店下载了
goosDetailshowClick() {//点击事件// console.log(this.productId,this.userId,'userId----获取')var u = navigator.userAgent;var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端if(isAndroid){// window.location.href = "simply://com.tqdk?type=live&id=" +326; /***打开app的协议,有安卓同事提供***/window.location.href = "simply://com.tqdk?productId="+this.productId+"&userId="+this.userId; window.setTimeout(function(){window.location.href = "https://pic.cklock.cn/app/app-release.apk"; },1000); }else if(isiOS){var loadDateTime = new Date();// window.location.href ="cn.com.cksmart.qkxz:///productId="+this.productId+"&userId="+this.userId;// https://pay.chienkun.net.cn/h5/ 是中间页,微信打开:没有下载时,跳到这个页面,提示浏览器打开(这个页面自动跳下载页)window.location.href ="https://pay.chienkun.net.cn/h5/?productId="+this.productId+"&userId="+this.userId;// var setTimeout = window.setTimeout(function() {// window.location.href = "https://apps.apple.com/cn/app/塞罕云-智能物联-生活服务/id1571682474";// var timeOutDateTime = new Date();// },3000);}
}
第二步:提示页和代码
<template><view class="index"><image src="../../static/index/share.jpg" mode=""></image></view>
</template><script>
var app = getApp()
export default {data() {return {};},onLoad() {var browser = {versions: function () {var u = navigator.userAgent, app = navigator.appVersion;return { //移动终端浏览器版本信息trident: u.indexOf('Trident') > -1, //IE内核presto: u.indexOf('Presto') > -1, //opera内核webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器iPad: u.indexOf('iPad') > -1, //是否iPadwebApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部};}(),language: (navigator.browserLanguage || navigator.language).toLowerCase()}if (browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面var ua = navigator.userAgent.toLowerCase();//获取判断用的对象console.log(ua,'ua----------------')if (ua.match(/MicroMessenger/i) == "micromessenger") { //在微信中打开window.location.href = "https://apps.apple.com/cn/app/塞罕云-智能物联-生活服务/id1571682474";}if (browser.versions.ios) {//是否在IOS浏览器打开window.location.href = "https://apps.apple.com/cn/app/塞罕云-智能物联-生活服务/id1571682474";} // if(browser.versions.android){//是否在安卓浏览器打开// window.location.href = "https://pic.cklock.cn/app/app-release.apk"; // }// if (ua.match(/WeiBo/i) == "weibo") {// //在新浪微博客户端打开// }// if (ua.match(/QQ/i) == "qq") {// //在QQ空间打开// }} else { //否则就是PC浏览器打开// window.location.href = "https://apps.apple.com/cn/app/塞罕云-智能物联-生活服务/id1571682474";}},methods: {}
};
</script><style lang="scss">.index {image {width: 100%;height: 210upx;}}
</style>