当前位置: 移动技术网 > 移动技术>移动开发>Android > 5+ API,APP更新逻辑部分

5+ API,APP更新逻辑部分

2020年07月23日  | 移动技术网移动技术  | 我要评论
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();
		}  
	}

},

在这里插入图片描述

本文地址:https://blog.csdn.net/qq_40745143/article/details/107519224

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网