更新问题?
发布于 5 年前 作者 leihou 7738 次浏览 来自 问答

微信小程序更新版本发布上线之后,强制更新线上版本不起作用

// 检测是否可以调用getUpdateManager检查更新

if (!wx.canIUse(“getUpdateManager”)) return;

 

console.log(wx.canIUse(“getUpdateManager”))

let updateManager = wx.getUpdateManager();

 

updateManager.onCheckForUpdate(function (res) {

 

console.log(“是否有新版本:” + res.hasUpdate);

if (res.hasUpdate) {

console.log(‘小程序更新了’)

 

updateManager.onUpdateReady(function () {

 

updateManager.applyUpdate();

})

updateManager.onUpdateFailed(function () {

 

wx.showModal({

title: ‘提示’,

content: ‘检查到有新版本,但下载失败,请稍后尝试’,

showCancel: false,

})

})

}else{

console.log(‘小程序没有没有没有没有没有没有没有没有更新’)

updateManager.applyUpdate();

}

});

3 回复
这是官方的小程序更新示例,我看到你写的好像是if判断出错了。检查一下是不是
const updateManager = wx.getUpdateManager()

updateManager.onCheckForUpdate(function (res) {
  // 请求完新版本信息的回调console.log(res.hasUpdate)
})

updateManager.onUpdateReady(function () {
  wx.showModal({
    title: '更新提示',
    content: '新版本已经准备好,是否重启应用?',
    success: function (res) {
      if (res.confirm) {
        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
        updateManager.applyUpdate()
      }
    }
  })
})

updateManager.onUpdateFailed(function () {
  // 新版本下载失败
})

文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/base/update/UpdateManager.html

安卓和苹果都有这个问题,我每次打印出来的都是没有更新,强制更新也不行

你说的是苹果吗? 苹果有一个问题,安卓现在没试过

回到顶部