登录  /  注册
博主信息
博文 70
粉丝 0
评论 2
访问量 90268
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
微信小程序发布新版本提示用户更新
搁浅
原创
1139人浏览过
  1. App({
  2. onShow: function (options) {
  3. this.updateApplet();
  4. },
  5. updateApplet: function (options) {
  6. //版本更新
  7. if (wx.canIUse('getUpdateManager')) {
  8. const updateManager = wx.getUpdateManager()
  9. updateManager.onCheckForUpdate((res)=>{
  10. // 请求完新版本信息的回调
  11. if (res.hasUpdate) {
  12. updateManager.onUpdateReady(()=>{
  13. wx.showModal({
  14. title: '更新提示',
  15. content: '新版本已经准备好,是否重启应用?',
  16. success: function (res) {
  17. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  18. if (res.confirm) {
  19. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  20. updateManager.applyUpdate()
  21. } else if (res.cancel) {
  22. //用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
  23. wx.showModal({
  24. title: '温馨提示~',
  25. content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
  26. showCancel: false, //隐藏取消按钮
  27. confirmText: "确定更新", //只保留确定更新按钮
  28. success: (res)=>{
  29. if (res.confirm) {
  30. updateManager.applyUpdate()
  31. }
  32. }
  33. })
  34. }
  35. }
  36. })
  37. })
  38. updateManager.onUpdateFailed(()=>{
  39. // 新的版本下载失败
  40. wx.showModal({
  41. title: '已经有新版本了哟~',
  42. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  43. })
  44. })
  45. }
  46. })
  47. }
  48. },
  49. })
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学