App({ globalData: { appName: "够de着", categoryId: NaN, }, onLaunch(options) { const that = this; that.autoUpdate(); // wx.getSystemInfo({ // success: function (res) { // const screenWidth = res.screenWidth // } // }) // 获取小程序启动参数 wx.setStorage({ key: "launch_options", data: options }); }, autoUpdate() { // 获取小程序更新机制兼容 if (wx.canIUse("getUpdateManager")) { // 是否支持​​小程序更新管理器 const updateManager = wx.getUpdateManager(); // 1. 检查小程序是否有新版本发布 updateManager.onCheckForUpdate((res) => { // 请求完新版本信息的回调 if (res.hasUpdate) { // 2. 小程序有新版本,则静默下载新版本,做好更新准备 updateManager.onUpdateReady(() => { wx.showModal({ title: "更新提示", content: "小程序已更新,为不影响您的使用,请点击确定进行更新。", showCancel: false, success(e) { if (e.confirm) { // 3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate(); } }, }); }); updateManager.onUpdateFailed(() => { // 新的版本下载失败 wx.showModal({ title: "更新提示", content: "因网络问题更新失败,请您删除当前小程序,重新搜索打开。", showCancel: false, }); }); } }); } else { // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示 wx.showModal({ title: "提示", content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。", }); } }, });