赞
踩
在app.js
加入以下代码:
// app.js App({ onLaunch() { this.globalData.sysinfo = wx.getSystemInfoSync() 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 () { // 新的版本下载失败 wx.showModal({ title: '更新提示', content: '新版本下载失败', showCancel: false }) }) }, globalData: { sysinfo: {}, } })
wx.getUpdateManager()
获取全局唯一的版本更新管理器,用于管理小程序更新UpdateManager.onCheckForUpdate
监听向微信后台请求检查更新结果事件UpdateManager.onUpdateReady
监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调UpdateManager.applyUpdate()
强制小程序重启并使用新版本。在小程序新版本下载完成后(即收到 onUpdateReady 回调)调用。UpdateManager.onUpdateFailed
监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。