uni-app H5端唤起App

在唤起应用页面用JS代码请求该协议,如果在3000ms内有应用程序能解析这个协议,那么就能打开该应用;如果超过3000ms就跳转到app下载页。

//直接调用这个方法即可
async checkInstallApp() {
		var 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 = ""; //找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 = "";//下载地址 可以直接跳转到appstore的
			}
		}
	}, 20);
}
android() {
	uni.showLoading({
		title: '加载中'
	});
	const currentTime = new Date().getTime();
	window.location.href = "";//找android工程师要 UrlSchemes
	// 启动间隔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 = "";//下载地址
			}
		}
	}, 20)
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值