You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 2.0KB

1 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. App({
  2. onLaunch: function (options) {
  3. // 版本更新
  4. if (wx.canIUse('getUpdateManager')) {
  5. const updateManager = wx.getUpdateManager()
  6. if (updateManager) {
  7. updateManager.onCheckForUpdate(function (res) {
  8. if (res.hasUpdate) {
  9. updateManager.onUpdateReady(function () {
  10. wx.showModal({
  11. title: '更新提示',
  12. content: '新版本已经准备好,是否重启应用?',
  13. success: function (res) {
  14. if (res.confirm) {
  15. updateManager.applyUpdate()
  16. } else if (res.cancel) {
  17. //用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
  18. wx.showModal({
  19. title: '温馨提示~',
  20. content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问',
  21. showCancel: false, //隐藏取消按钮
  22. confirmText: "确定更新", //只保留确定更新按钮
  23. success: function (res) {
  24. if (res.confirm) {
  25. //下载新版本,并重新应用
  26. updateManager.applyUpdate()
  27. }
  28. }
  29. })
  30. }
  31. }
  32. })
  33. })
  34. updateManager.onUpdateFailed(function () {
  35. wx.showModal({
  36. title: '已经有新版本了哟~',
  37. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  38. })
  39. })
  40. }
  41. })
  42. }
  43. } else {
  44. wx.showModal({
  45. title: '提示',
  46. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  47. })
  48. };
  49. },
  50. })