小程序更新版本后,写了更新版本的代码,但是不起作用,没有弹框
/*更新版本*/
autoUpdate() {
let that = this
// 获取小程序更新机制兼容
if (wx.canIUse(‘getUpdateManager’)) {
const updateManager = wx.getUpdateManager()
//检查小程序是否有新版本发布
updateManager.onCheckForUpdate(async(res) => {
// 请求完新版本信息的回调
if (res.hasUpdate) {
//检测到新版本,需要更新,给出提示
wx.showModal({
title: ‘更新提示’
content: ‘检测到新版本,是否重启小程序?’
showCancel: false
confirmColor: “#f6d201”
success: function(res) {
if (res.confirm) {
//用户确定下载更新小程序,小程序下载及更新静默进行
that.downloadUpdate(updateManager)
}
}
})
}
})
}
},
/*下载小程序新版本并重新启用*/
downloadUpdate(data) {
let that = this
wx.showLoading()
//静默下载更新小程序新版本
data.onUpdateReady((res) => {
wx.hideLoading()
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启
data.applyUpdate()
})
data.onUpdateFailed(() => {
wx.hideLoading()
// 新的版本下载失败
hshowModal(“已经有新版本了哟”, “已经有新版本了,请您删除当前小程序,重新搜索打开”
})
}
真机上没有出现这个弹框
