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: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'})})}})}},})
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号