1)微信開發(fā)者工具上可以通過「編譯模式」下的「下次編譯模擬更新」開關(guān)來調(diào)試
2)小程序開發(fā)版/體驗(yàn)版沒有「版本」概念,所以無法在開發(fā)版/體驗(yàn)版上測試更版本更新情況
在App.js里面添加
onLaunch () {
? if (wx.canIUse('getUpdateManager')) {
? const updateManager = wx.getUpdateManager()
? updateManager.onCheckForUpdate(function (res) {
? ? console.log('onCheckForUpdate====', res)
? ? // 請(qǐng)求完新版本信息的回調(diào)
? ? if (res.hasUpdate) {
? ? console.log('res.hasUpdate====')
? ? updateManager.onUpdateReady(function () {
? ? ? wx.showModal({
? ? ? title: '更新提示',
? ? ? content: '新版本已經(jīng)準(zhǔn)備好,是否重啟應(yīng)用?',
? ? ? success: function (res) {
? ? ? ? console.log('success====', res)
? ? ? ? // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
? ? ? ? if (res.confirm) {
? ? ? ? // 新的版本已經(jīng)下載好,調(diào)用 applyUpdate 應(yīng)用新版本并重啟
? ? ? ? updateManager.applyUpdate()
? ? ? ? }
? ? ? }
? ? ? })
? ? })
? ? updateManager.onUpdateFailed(function () {
? ? ? // 新的版本下載失敗
? ? ? wx.showModal({
? ? ? title: '已經(jīng)有新版本了喲~',
? ? ? content: '新版本已經(jīng)上線啦~,請(qǐng)您刪除當(dāng)前小程序,重新搜索打開喲~'
? ? ? })
? ? })
? ? }
? })
? }
}