代码片段:
App({ onShow: function (options) { this.updateApplet(); }, updateApplet: function (options) { //版本更新 if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate((res)=>{ // 请求完新版本信息的回调 if (res.hasUpdate) { updateManager.onUpdateReady(()=>{ wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { // res: {errMsg: "showModal: ok", cancel: false, confirm: true} if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } else if (res.cancel) { //用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了 wx.showModal({ title: '温馨提示~', content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~', showCancel: false, //隐藏取消按钮 confirmText: "确定更新", //只保留确定更新按钮 success: (res)=>{ if (res.confirm) { updateManager.applyUpdate() } } }) } } }) }) updateManager.onUpdateFailed(()=>{ // 新的版本下载失败 wx.showModal({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) } }, })
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。