uniapp微信小程序获取小程序新版本

function checkUpdate() {
  //使用该接口,可以获知是否有新版本小程序、新版本是否下载好以及应用新版本的能力。
  const updateManager = uni.getUpdateManager()
  updateManager.onCheckForUpdate(function (res) {
    // 请求完新版本信息的回调
    console.log(res.hasUpdate)
  })
  updateManager.onUpdateReady(function () {
    uni.showModal({
      title: '更新提示',
      content: '新版本已经准备好,准备重启应用...',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
          updateManager.applyUpdate()
        }
      },
    })
  })
  updateManager.onUpdateFailed(function () {
    // 新的版本下载失败
    uni.showModal({
      title: '更新提示',
      content: '新版本下载失败',
      showCancel: false,
    })
  })
}

 

posted @ 2024-08-27 10:25  行走的蒲公英  阅读(16)  评论(0编辑  收藏  举报