美文网首页
微信小程序检测版本更新然后刷新小程序

微信小程序检测版本更新然后刷新小程序

作者: Pluto_7a23 | 来源:发表于2023-03-02 09:52 被阅读0次

当我们把微信小程序提交审核,通过后进行发布,如果用户本地使用小程序有时就会出现缓存,打开的小程序还是旧的版本。遇到这个问题可以通过删除小程序并重新进入的方式来清除缓存,但这样明显不是个好办法
利用uni-app中的uni.getUpdateManager()来处理
官网链接 https://uniapp.dcloud.net.cn/api/other/update.html#getupdatemanager

const updateManager = uni.getUpdateManager();

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

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

});

updateManager.onUpdateFailed(function (res) {
// 新的版本下载失败
});


相关文章

网友评论

      本文标题:微信小程序检测版本更新然后刷新小程序

      本文链接:https://www.haomeiwen.com/subject/txkjldtx.html