uni微信小程序强制用户更新版本

强制更新的代码参考官方文档

uni.getUpdateManager() | uni-app官网

我这边的如下:

javascript 复制代码
//检查版本更新
			const updateManager = uni.getUpdateManager();

			updateManager.onCheckForUpdate(function (res) {
				// 请求完新版本信息的回调
				console.log(res.hasUpdate, "是否版本更新");
			});

			updateManager.onUpdateReady(function (res) {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好,是否重启应用?',
					showCancel: false,
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});

			});

			updateManager.onUpdateFailed(function (res) {
				// 新的版本下载失败
				console.log('download error')
				uni.showModal({
					title: '提示',
					content: '新版小程序下载失败\n请自行退出程序,手动卸载本程序,再运行',
					confirmText: "知道了"
				});
			});

效果:

相关推荐
爱勇宝2 天前
我想认真做一件小事:让孩子和家长更好地互动
微信小程序·小程序·云开发
唯火锅不可辜负2 天前
避坑指南:iOS 下 scroll-view 嵌套 fixed 布局的“翻车”现场与修复
微信小程序
didiplus2 天前
运维人的随身神器:我把25个常用工具塞进了微信小程序
微信小程序
一份执念2 天前
uni-app 小程序分包限制处理与主包体积优化实战
前端·微信小程序
一份执念2 天前
ECharts 安装与使用完全指南:从全量引入到小程序分包优化
微信小程序·echarts
skiyee4 天前
🔥UniApp 仅需 5 行代码!实现所有页面中控制应用主题变化
前端·微信小程序
Jinkey5 天前
要用户手机号真的是为了打骚扰电话吗?浅谈微信生态会员账号体系与资产合并
后端·微信·微信小程序
用户4324281061147 天前
微信小程序从0到1接入微信支付的完整攻略
微信小程序
spmcor9 天前
微信小程序 setStorageSync 踩坑实录:别让"顺手一存"变成"隐形炸弹"
微信小程序
用户4324281061149 天前
小程序埋点设计规范:如何设计可扩展的数据采集体系
微信小程序