编程 微信小程序热更新

2024-11-18 15:08:49 +0800 CST views 4204

微信小程序写好发布后,正常用户版本更新需要删除程序。重新搜索才可以。又重新阅读了微信文档,发现支持热更新。

// 获取小程序更新机制兼容
    if (wx.canIUse('getUpdateManager')) {
      const updateManager = wx.getUpdateManager()
      updateManager.onCheckForUpdate(function (res) {
        // 请求完新版本信息的回调
        if (res.hasUpdate) {
          updateManager.onUpdateReady(function () {
            wx.showModal({
              title: '更新提示',
              content: '新版本已经准备好,是否重启应用?',
              success: function (res) {
                if (res.confirm) {
                  // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                  updateManager.applyUpdate()
                }
              }
            })
          })
          updateManager.onUpdateFailed(function () {
            // 新的版本下载失败
            wx.showModal({
              title: '已经有新版本了哟~',
              content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
            })
          })
        }
      })
    } else {
      // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
      })
    }
复制全文 生成海报 微信 小程序 开发

推荐文章

php strpos查找字符串性能对比
2024-11-19 08:15:16 +0800 CST
php指定版本安装php扩展
2024-11-19 04:10:55 +0800 CST
MyLib5,一个Python中非常有用的库
2024-11-18 12:50:13 +0800 CST
测试文章中文
2026-06-14 21:19:50 +0800 CST
什么是Vue实例(Vue Instance)?
2024-11-19 06:04:20 +0800 CST
Golang Select 的使用及基本实现
2024-11-18 13:48:21 +0800 CST
四舍五入五成双
2024-11-17 05:01:29 +0800 CST
Vue3中的v-for指令有什么新特性?
2024-11-18 12:34:09 +0800 CST
资源文档库
2024-12-07 20:42:49 +0800 CST
支付宝批量转账
2024-11-18 20:26:17 +0800 CST
程序员茄子在线接单