• 检测小程序版本更新提示


    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: '新版本下载失败,请删除当前小程序,重新搜索下载~'
                })
              })
            }
          })
            
        }
      }

     

     

      

  • 相关阅读:
    455. Assign Cookies
    [leetcode]Linked List Cycle
    *[topcoder]GooseTattarrattatDiv1
    [topcoder]FoxAndChess
    *[topcoder]TheTree
    *[topcoder]LittleElephantAndBalls
    *[topcoder]HexagonalBoard
    *[topcoder]AstronomicalRecords
    *[topcoder]LittleElephantAndIntervalsDiv1
    [topcoder]IncrementAndDoubling
  • 原文地址:https://www.cnblogs.com/cmy1996/p/11751932.html
Copyright © 2020-2023  润新知