From ed36a0db0a3b6dfdf2ceff30c73416f15c552a67 Mon Sep 17 00:00:00 2001 From: lik Date: Wed, 7 Oct 2026 16:57:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=89=E6=96=B0=E7=89=88=E6=9C=AC=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index a2aa367..0eed6d7 100644 --- a/app.js +++ b/app.js @@ -123,32 +123,49 @@ App({ }, checkUpdate() { + // 老基础库(< 1.9.90)没有 getUpdateManager,先挡一层: + // 否则下面直接 .onCheckForUpdate 会抛 TypeError + if (!wx.canIUse('getUpdateManager')) { + return; + } + // 获取小程序更新管理器实例 const updateManager = wx.getUpdateManager(); // 监听检查更新事件,当小程序有新版本时会触发此回调 updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 - console.log(res.hasUpdate); // 打印是否有新版本 + console.log('[App] 是否有新版本:', res.hasUpdate); // 打印是否有新版本 }); // 监听更新准备就绪事件,当新版本下载完成时会触发此回调 updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', - content: '新版本已经准备好,可以重启应用小程序了!', + content: '新版本已经准备好,是否重启应用?', + confirmText: '立即重启', + cancelText: '稍后', success(res) { if (res.confirm) { // 用户确认更新,调用 applyUpdate 应用新版本并重启小程序 updateManager.applyUpdate(); + return; } + // 用户选了「稍后」:新版本此时不会生效,要等下次冷启动才自动应用。 + // 这里必须说清楚,否则用户以为已经升级完了 + wx.showToast({ + title: '下次打开将自动更新', + icon: 'none' + }); } }); }); // 监听更新失败事件,当新版本下载失败时会触发此回调 updateManager.onUpdateFailed(function () { - // 新版本下载失败,可以在这里处理失败逻辑,例如提示用户稍后再试 + // 下载失败没有可交给用户的动作(微信会在下次启动时重试), + // 只留日志便于线上排查,不打断用户 + console.warn('[App] 新版本下载失败'); }); },