From dfddcd52eb76d19422adf0e37ef36987bfd2d2e2 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 10 Apr 2019 14:57:30 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0][=E6=96=B0=E5=A2=9E]:=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E9=83=A8=E5=88=86=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=9C=AA=E5=8F=8A=E6=97=B6=E6=9B=B4=E6=96=B0=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app.js b/app.js index 1e3b73b..ecec6c1 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,38 @@ App({ console.log("onUnload ") var that = this; that.globalData.sceneAddress = options.scene; + + if (wx.canIUse('getUpdateManager')) { + const updateManager = wx.getUpdateManager() + updateManager.onCheckForUpdate(function (res) { + console.log('onCheckForUpdate====', res) + // 请求完新版本信息的回调 + if (res.hasUpdate) { + console.log('res.hasUpdate====') + updateManager.onUpdateReady(function () { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success: function (res) { + console.log('success====', res) + // res: {errMsg: "showModal: ok", cancel: false, confirm: true} + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate() + } + } + }) + }) + updateManager.onUpdateFailed(function () { + // 新的版本下载失败 + wx.showModal({ + title: '已经有新版本了哟~', + content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' + }) + }) + } + }) + } }, /** * 获取地址位置信息