uniapp 检测小程序更新、app更新

1.小程序检测,更新

//在app.vue中
<script>
   Update(){
	const updateManager = uni.getUpdateManager();
	updateManager.onCheckForUpdate(function (res) {
	  // 请求完新版本信息的回调
	});
	
	updateManager.onUpdateReady(function (res) {
	  uni.showModal({
	    title: '更新提示',
	    content: '新版本已经准备好,是否重启应用?',
	    success(res) {
	      if (res.confirm) {
	        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
	        updateManager.applyUpdate();
	      }
	    }
	  });
	});
	
	updateManager.onUpdateFailed(function (res) {
	  // 新的版本下载失败
	});
}	
    }
</script>
//生命周期中调用检测
onShow(){
	this.Update()
}

2.app检测、更新

视图构造

在这里插入图片描述

data中的定义

在这里插入图片描述

/**检查app版本*/
//目前在nvue页面定义的,不排除vue页面
			updateApp() {
				// #ifdef APP-NVUE
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
				//定义接口比对版本号
					getAppUpdate({
						type: 1
					}).then(res => {
						if (res.resultCode == '000000') {
							if (res.data) {
								this.appInform = res.data;
								if (res.data.appVersion != wgtinfo.version) {
									this.showUpdate = true;
								}
							}
						}
					}).catch(error => {
						console.log("0000000000000000", error)
					})
				})
				// #endif
			},```
```cpp
//showLoading控制组件是否显示的
		updateStart(type) {
				let _this = this;
				if (type == 2) return _this.showUpdate = false;
				if (type == 1) {
					// _this.showUpdate=false;
					if (_this.showLoading) return;
					uni.showLoading({
						title: '更新中,请稍后...'
					})
					_this.showLoading = true;
					// plus.runtime.openURL(this.appInform.appUrl);
					var dtask = plus.downloader.createDownload(_this.appInform.appUrl, {}, function(d, status) {
						uni.hideLoading();
						_this.showLoading = false;
						// 下载完成
						if (status == 200) {
							plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(
								error) {
								uni.showToast({
									title: '安装失败',
									duration: 1500
								});
							})
						} else {
							uni.showToast({
								title: '更新失败',
								duration: 1500
							});
						}
					});
					dtask.start();
				}
			},```

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值