From bff0f7867faa25354916b81d4eaae3aaa9b8f308 Mon Sep 17 00:00:00 2001 From: DEV_DSW <562304744@qq.com> Date: Mon, 8 Sep 2025 15:15:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/UpdateManager.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 utils/UpdateManager.js diff --git a/utils/UpdateManager.js b/utils/UpdateManager.js new file mode 100644 index 0000000..5d30e29 --- /dev/null +++ b/utils/UpdateManager.js @@ -0,0 +1,25 @@ +export const updateManager = () => { + const updateManager = uni.getUpdateManager(); + + // 当向小程序后台请求完新版本信息,会进行回调 + updateManager.onCheckForUpdate((res) => { + console.log("onCheckForUpdate res:", res.hasUpdate); + }); + + // 当新版本下载完成,会进行回调 + updateManager.onUpdateReady(() => { + uni.showModal({ + title: "更新提示", + content: "新版本已经准备好,是否重启应用?", + success: (res) => { + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate(); + } + }, + }); + }); + + // 当新版本下载失败,会进行回调 + updateManager.onUpdateFailed(() => {}); +};