cmy1996

 

const updateManager = wx.getUpdateManager()

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

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

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

 

async onLaunch() {
    let res = wx.getSystemInfoSync();
      if (!res.version || !compareVersion(res.version, \'6.5.13\')) {
        wx.showModal({
          title: \'提示\',
          content: \'当前微信版本过低,功能支持不完善,请升级到最新微信版本后重试。\'
        })
      }
      this.checkNewVersion()
}

// 检查版本更新
  checkNewVersion() {
    if(wx.canIUse(\'getUpdateManager\')) { // 用户版本更新
      let updateManager = wx.getUpdateManager()
      updateManager.onCheckForUpdate((res) => {
        // 请求完新版本信息的回调
        if(res.hasUpdate) {
          updateManager.onUpdateReady(() => {
            wx.showModal({
              title: \'更新提示\',
              content: \'新版本已经准备好,是否重启应用?\',
              success: res => {
                if(res.confirm) {
                // 新版本已经下载好,调用applyUpdate应用新版本,并且重启
                  updateManager.applyUpdate()
                }
              }
            })
          })
          updateManager.onUpdateFailed(() => { // 新版本下载失败 需要用户手动旧版本删除,下载新版本
            wx.showModal({
              title: \'更新失败\',
              content: \'新版本下载失败,请删除当前小程序,重新搜索下载~\'
            })
          })
        }
      })
        
    }
  }

 

 

 

 

  

分类:

技术点:

相关文章: