小程序版本更新(uni-app)

App.vue文件
 
onLaunch: function() {
    console.log("App Launch");
    const updateManager = uni.getUpdateManager();
    updateManager.onCheckForUpdate(function(res) {
      // 请求完新版本信息的回调
      if (res.hasUpdate) {
        updateManager.onUpdateReady(function(res2) {
          uni.showModal({
            title: "更新提示",
            content: "发现新版本,请更新...",
            confirmColor: "#E30012",
            showCancel: false,
            success(res2) {
              if (res2.confirm) {
                // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                updateManager.applyUpdate();
              }
            },
          });
        });
      }
    });
    updateManager.onUpdateFailed(function(res) {
      // 新的版本下载失败
      uni.showModal({
        title: "提示",
        content: "新版本下载失败,请检查网络!",
      });
    });
  },
posted @ 2021-06-25 09:53  忘忧人  阅读(201)  评论(0编辑  收藏  举报