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

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

需求背景
  • 最近基于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: '知道了'
            })
          })
        }
      })
    
    
  • 解决。

猜你喜欢

转载自blog.csdn.net/qq_34917408/article/details/128733010
今日推荐