ps: 自用的,在此简单记录
//判断应用市场
judeBrand() {
const userAgent = navigator.userAgent.toLowerCase()
const isIphone = userAgent.match(/(iphone|ipad|ipod)/i);
const isHuawei = userAgent.match(/huawei/i);
const isHonor = userAgent.match(/honor/i);
const isOppo = userAgent.match(/oppo/i);
const isOppoR15 = userAgent.match(/pacm00/i);
const isVivo = userAgent.match(/vivo/i);
const isXiaomi = userAgent.match(/mi\s/i);
const isXIAOMI = userAgent.match(/xiaomi/i);
const isXiaomi2s = userAgent.match(/mix\s/i);
const isRedmi = userAgent.match(/redmi/i);
if (isIphone) {
return 'iphone'
} else if (isHuawei || isHonor) {
return 'huawei';
} else if (isOppo || isOppoR15) {
return 'oppo';
} else if (isVivo) {
return 'vivo';
} else if (isXiaomi || isRedmi || isXiaomi2s || isXIAOMI) {
return 'xiaomi';
} else {
return 'other'
}
},
//判断是否从微信中打开
isWeixin(){
return /MicroMessenger|WeXin|WeChat/g.test(navigator.userAgent)
},
download(){
if(this.isWeixin()){
alert("请跳转至浏览器中访问");
return;
}
let ua = navigator.userAgent;
let isAndroid = ua.indexOf("Android") > -1 || ua.indexOf("Linux") > -1; //android终端
let isIOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
let hidden = window.document.hidden || window.document.mozHidden || window.document.msHidden || window.document.webkitHidden;
let by = 'com.twins.som'; //应用包名
if (typeof hidden === undefined || hidden === false) {
if (isAndroid) {
// 跳转 安卓应用市场地址
switch (this.judeBrand()) {
case 'xiaomi':
window.location.replace(`mimarket://details?id=`+by)
break
case 'huawei':
window.location.replace(`appmarket://details?id=`+by)
break
case 'vivo':
window.location.replace(`vivomarket://details?id=`+by)
break
case 'oppo':
window.location.replace(`oppomarket://details?id=`+by)
break
default:
window.location.replace('') //服务器地址
break
}
} else if (isIOS) {
// 跳转 app store 地址
window.location.replace(`https://apps.apple.com/cn/app/`+by)
}
}
},