微信小程序版本自动更新用户感知提示方案总结

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

微信小程序版本自动更新用户感知提示方案总结

需求背景
  • 最近基于uniapp开发微信小程序上线后在迭代版本后期望自动更新提示。
  • 使感知。
解决方案
  • 使用全局唯一的对象 updateManager。

  • // 方案如下
    
      const updateManager = uni.getUpdateManager()
      updateManager.onCheckForUpdate((res) => {
        if (res.hasUpdate) {
          updateManager.onUpdateReady(() => {
            uni.showModal({
              title: '更新提示',
              content: '新版本已经准备好是否重启应用',
              success(res) {
                if (res.confirm) {
                  updateManager.applyUpdate()
                }
              }
            })
          })
          updateManager.onUpdateFailed(() => {
            uni.showModal({
              content: '新版本更新失败请关闭应用后重启',
              showCancel: false,
              confirmText: '知道了'
            })
          })
        }
      })
    
    
  • 解决。

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6