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()