5+ API,APP更新逻辑部分

let _this = this;
let version = this.android.version.split(".").join(""); // 需要更新的版本 1.0.1  === 101;//这个是接口返回的最新版本号
//let version = 100;
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
	let time_version = widgetInfo.versionCode; // 当前APP的版本 : 100
	if (time_version < version) { // 当前版本小于更新版本,提示更新,
		_this.show2 = true; //可以弹出更新提示框
	} else {
		plus.nativeUI.toast('已是最新版本');
		_this.$emit('closeVersion'); //关闭show组件
	}
})

//升级
up() {
	let _this = this;
	this.progress = 0;
	this.progressShow = true; //切换进度条显示
	//开启下载任务
	var dtask = plus.downloader.createDownload("http://www.qc888.info/app/qicheng1.0.3.apk?1595408102", {}, function(d, status) {
		if (status == 200) {
			plus.runtime.install(d.filename); //下载成功安装apk
		} else {
			console.log("失败: " + status);
		}
	});
	dtask.addEventListener("statechanged", onStateChanged, false);//监听下载进度
	dtask.start(); //开始下载
	
	//监听下载进度
	function onStateChanged(download, status) {
		if(Number(download.downloadedSize)>0){
			_this.progress = Math.ceil(download.downloadedSize / download.totalSize* 100);
		}
		if(download.state == 4 && status == 200){
			// 下载完成,清除下载任务
			plus.downloader.clear();
		}  
	}

},

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值