微信小程序版本自动更新提示
onLaunch: function () {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,请重启应用!',
confirmText: '重启',
showCancel: false,
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '系统提示',
content: '小程序新版本更新失败,请您删除当前小程序,重新搜索打开'
})
})
}
})
}
}