微信登录

更新标识 - 提示更新 - 检测到新版本

app.js

  1. App({
  2. onLaunch() {
  3. var that = this;
  4. that.update_new_version() //更新新版
  5. },
  6. //更新新版
  7. update_new_version: function (params) {
  8. this.globalData.sysinfo = wx.getSystemInfoSync()
  9. const updateManager = wx.getUpdateManager()
  10. updateManager.onCheckForUpdate(function (res) {
  11. // 请求完新版本信息的回调
  12. console.log(res.hasUpdate)
  13. })
  14. updateManager.onUpdateReady(function () {
  15. wx.showModal({
  16. title: '更新提示',
  17. content: '新版本已经准备好,是否重启应用?',
  18. success: function (res) {
  19. if (res.confirm) {
  20. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  21. updateManager.applyUpdate()
  22. }
  23. }
  24. })
  25. })
  26. updateManager.onUpdateFailed(function () {
  27. // 新的版本下载失败
  28. wx.showModal({
  29. title: '更新提示',
  30. content: '新版本下载失败',
  31. showCancel: false
  32. })
  33. })
  34. },
  35. globalData: {
  36. sysinfo: {},
  37. }
  38. })