微信小程序版本更新并重新启动小程序

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-17 08:12   11   0

  //<<<------- // 版本更新
  checkUpdateVersion: function () {
    var that=this
    //创建 UpdateManager 实例
    const updateManager = wx.getUpdateManager();
    //检测版本更新
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      if (res.hasUpdate == true) {
        //监听小程序有版本更新事件
        updateManager.onUpdateReady(function () {
           wx.showModal({
            title: '[灯塔],更新提示!!!',
             content: '新版本已经准备好,是否重启应用?',
             success(res) {
              if (res.confirm) {
          // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
          updateManager.applyUpdate();
          // }
          // }
          // })
        })

        updateManager.onUpdateFailed(function () {

          // 新版本下载失败
          wx.showModal({
            title: '[灯塔]已经有新版本咯~',
            content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索[灯塔]打开呦~',
          })
        })
      } 
    })
    //----------->>>>
  },

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP