赞
踩
<template>
<view class="content">
<button type="primary" @tap="tapOpen">打开APP</button>
<a href="testshop://params">打开APP</a>
</view>
</template>
<script>
export default {
methods: {
tapOpen() {
let u = navigator.userAgent;
var isWeixin = u.toLowerCase().indexOf('micromessenger') !== -1; // 微信内
if (isWeixin) {
alert('请在浏览器中打开')
return false;
}
const platform = uni.getSystemInfoSync().platform;
if (platform === 'ios') {
this.ios()
}
if (platform === 'android') {
this.android()
}
},
ios() {
uni.showLoading({
title: '加载中...'
});
const currentTime = +(new Date());
window.location.href = "testshop"; //找ios工程师要 UrlSchemes
//启动间隔20ms运行的定时器,并检测累计消耗时间是否超过3000ms,超过则结束
let _count = 0,
timer;
timer = setInterval(function() {
_count++;
const endTime = +(new Date()) - currentTime;
if (_count >= 100 || endTime > 3000) {
uni.hideLoading()
clearInterval(timer);
let hidden = window.document.hidden || window.document.mozHidden || window.document
.msHidden || window.document.webkitHidden;
if (typeof hidden == "undefined" || hidden == false) {
//App store下载地址
window.location.href = "https://ide.dcloud.net.cn/build/download/9cb7b510-98cc-11ee-80f8-818737b5217e"; //下载地址 可以直接跳转到appstore的
}
}
}, 20);
},
android() {
// uni.showLoading({
// title: '加载中...'
// });
// const currentTime = new Date().getTime();
// window.location.href = "nftmall://"; //找android工程师要 UrlSchemes
let ifr = document.createElement("iframe");
ifr.src = "testshop://params";
ifr.style.display = "none";
document.body.appendChild(ifr);
// 启动间隔20ms运行的定时器,并检测累计消耗时间是否超过2000ms,超时则结束
// let _count = 0,
// timer;
// timer = setInterval(() => {
// _count++;
// const endTime = new Date().getTime() - currentTime;
// if (_count >= 200 || endTime > 5000) {
// uni.hideLoading()
// clearInterval(timer);
// let hidden = window.document.hidden || window.document.mozHidden || window.document
// .msHidden || window.document.webkitHidden;
// if (typeof hidden == "undefined" || hidden == false) {
// //App store下载地址
// window.location.href = "https://ide.dcloud.net.cn/build/download/9cb7b510-98cc-11ee-80f8-818737b5217e"; //下载地址
// }
// }
// }, 20)
}
}
}
</script>
*在manifest.json的"app-plus"->“distribute”->"android"节点下添加schemes数据:
“schemes” : “testshop”
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。