app.js页面
// app.js
App({
onLaunch() {
// 更新检测
const updateManager = wx.getUpdateManager();
// 检查更新
updateManager.onCheckForUpdate(res => {
if (res.hasUpdate) {
// 有新版本
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新失败',
content: '请删除小程序后重新安装',
});
});
} else {
console.log('当前已是最新版本,可选处理逻辑')
}
});
},
})