检测代码版本更新
发布于 5 年前 作者 fangzhang 5796 次浏览 来自 问答

下面的这些代码写到了app.js中的

onLaunch方法里面

加到正式环境中并没有用,有大神来帮忙指点一下这个问题吗?


const updateManager = wx.getUpdateManager()

console.log(updateManager)

updateManager.onCheckForUpdate(function (res) {

// 请求完新版本信息的回调

//console.log(res)

console.log(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: ‘新版本下载失败’,

showCancel: false

})

})

3 回复

你好,如果用户已经更新了的话,是不会有提示更新的

我觉得wx.getUpdateManager()不应该写在App.js的onLaunch方法里面,应该写在启动页面的onShow方法里面,原因是onLaunch方法并不是每次打开小程序都会执行(热启动时并不会执行),所以并不会及时提示版本更新

你好,微信客户端大概有 5 分钟缓存,如果太快操作,可能会拉不到新版本

回到顶部