摘自:https://www.jianshu.com/p/9d679e5f8072
注意要點:1.每次更新,需要帶上版本號,版本號不能與上次的相同
2.app.js 中增加一個 onLaunch 生命週期函數,然後把微信的這段示例代碼丟進去,在編譯模式中勾選“下次編譯時模擬更新”,編譯時就可以看到效果了。
App({
onLaunch: function(){
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 請求完新版本信息的回調
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已經準備好,是否重啓應用?',
success: function (res) {
if (res.confirm) {
// 新的版本已經下載好,調用 applyUpdate 應用新版本並重啓
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下載失敗
})
}
})