//app.jsApp({onLaunch:function(options){this.autoUpdate()},autoUpdate:function(){varself=thisif(wx.canIUse('getUpdateManager')){constupdateManager=wx.getUpdateManager()//检查小程序是否有新版本发布updateManager.onCheckForUpdate(function(res){//请求完新版本的信息回调if(res.hasUpdate){wx.showModal({title:'更新提示',content:'检查到新版本,是否下载新版本并重启小程序?',success:function(res){if(res.confirm){//下载self.downloadAndUpdate(updateManager)}elseif(res.cancel){//点击取消,做强制更新操作wx.showModal({title:'温馨提示',content:'必须强制更新哦,旧版本无法正常使用',showCancel:false,//隐藏取消按钮confirmText:'确定更新',success:function(res){if(res.confirm){//再次调用下载,并重启self.downloadAndUpdate(updateManager)}}})}}})}})}else{//增加用户体验,给出友好提示wx.showModal({title:'提示',content:'当前微信版本过低,无法使用该功能,请升级后重试。'})}},/下载新版本并重启/downloadAndUpdate:function(updateManager){varself=thiswx.showLoading();//监听小程序有版本更新事件,客户端主动触发updateManager.onUpdateReady(function(){wx.hideLoading();//新版本下载好,调用applyUpdateupdateManager.applyUpdate()})//监听小程序更新失败事件updateManager.onUpdateFailed(function(){wx.showModal({title:'已经有新版了哦',content:'请你删除当前小程序,进行升级哦'})})}})用开发工具测试的时候,需要添加编译模式

并勾选如下复选框

内容参考