zoukankan      html  css  js  c++  java
  • 检测小程序版本更新提示

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

     

     

      

  • 相关阅读:
    定时器工厂
    无聊js画了个菱形
    盒模型之滚动条
    无聊,纯css写了个评分鼠标移入的效果
    json属性名为什么要双引号?
    原生js写的一个简单slider
    D2 前端技术论坛总结(上)
    第一天,入坑 —— 2014.10.24
    获取div相对文档的位置
    我们平时是怎么写html和css的?
  • 原文地址:https://www.cnblogs.com/cmy1996/p/11751932.html
Copyright © 2011-2022 走看看