uniapp 之更新版本

步骤一:在app.vue 中

//获取本地版本信息
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
		console.log(wgtinfo, 'wgtinfowgtinfowgtinfo')
		uni.setStorage({
			key: 'wgtinfoVersionCode',
			data: wgtinfo
		})
	})

步骤二:在登录页

//获取版本列表
getSysVersion() {
	const _this = this;
	//获取缓存中,当前app的版本号
	uni.getStorage({
		key: 'wgtinfoVersionCode',
		success: (res) => {
			_this.wgtinfoVersionCode = res.data;
			uni.request({
				url: url,//列表接口地址
				method: 'GET',
				sslVerify: false,
				data: {},
				success(res) {
					if (res.data.code === 200) {
						let appversion = res.data.result.version
						var appUrl = res.data.result.fileUrl;
						console.log(appUrl, 'appUrlappUrl')
						// 后端返回的app版本和当前app版本比较
						if (appversion != _this.wgtinfoVersionCode.version) {
							uni.showModal({
								title: "发现新版本",
								content: "确认下载更新",
								success: (res) => {
									if (res.confirm ==true) { //当用户确定更新,执行更新,下面方法进行下载app
										_this.appdownLoad(res.data[0]);
									} else {
										return false
									}
								}
							})
						} 
					}
				},
				fail() {
				}
			})
		},

	})
},
appdownLoad(url) {
	console.log(url, '下载app地址')
	
	var that = this;
	uni.showLoading({
		title: '安装包下载中……'
	})
	##下载文件的方法请查看另一篇 下载与保存

	plus.runtime.install( //安装
		downloadResult
			.filename,//文件的保存地址
		{
			force: true
		},
		function(res) {
			utils.showToast('更新成功,重启中');
			plus.runtime.restart();
		}
	);

}



  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值