1. 在 app.js 文件中加入方法:
hasNewBanben() {
console.log('校验更新')
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate((res1) => {
if (res1.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
updateManager.applyUpdate();
}
})
console.log('正在更新中......')
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已经有新版本呦~',
content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开哦~',
})
})
}
})
} else {
wx.showModal({
title: '溫馨提示',
content: '当前微信版本过低,请升级到最新微信版本后重试。'
})
}
}
2. 在 app.js 中的 onLaunch 调用1中方法即可:
this.hasNewBanben()