小程序版本更新后,有的机型用户看到的还是旧版,和服务端不同步。求解决啊?
发布于 7 年前 作者 minjiang 8927 次浏览 来自 官方Issues

小程序版本更新后,有的机型用户看到的还是旧版,和服务端不同步。生命周期onShow里面加了强制更新,一部分手机还是没用,求解决啊?

  onShow: function() {
    console.log('热更新')
    if (wx.canIUse("getUpdateManager")) {
      const updateManager = wx.getUpdateManager();
      updateManager.onCheckForUpdate(function(res) {
        console.log("onCheckForUpdate====11111", res);
        // 请求完新版本信息的回调
        if (res.hasUpdate) {
          console.log("res.hasUpdate====");
        }
      });
      updateManager.onUpdateReady(function(res) {
        console.log(111, res);
        wx.showModal({
          title: "版本更新",
          content: "新版本已经准备好,确定重启应用?",
          showCancel: false,
          success: function(res) {
            console.log("success====", res);
            // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
            if (res.confirm) {
              // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
              updateManager.applyUpdate();
            }
          }
        });
      });
      updateManager.onUpdateFailed(function() {
        // 新的版本下载失败
        wx.showModal({
          title: "已经有新版本了哟~",
          content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~"
        });
      });
    }
  },
3 回复

删除重新加载可以吗?

你从这个版本才开始加的版本更新吗?

微信太旧,连if (wx.canIUse("getUpdateManager")) {都没有的?
生命周期onShow,这个放到常用页面的onShow试试吧,生命周期的onShow会一直触发吗
回到顶部