update.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * 检查微信小程序更新
  3. */
  4. export const CheckWxUpdate = (useTip = false) => {
  5. if (uni.canIUse('getUpdateManager')) {
  6. const updateManager = wx.getUpdateManager();
  7. updateManager && updateManager.onCheckForUpdate((res) => {
  8. if (res.hasUpdate) {
  9. updateManager.onUpdateReady(() => {
  10. uni.showModal({
  11. title: '更新提示',
  12. content: '新版本已经准备就绪,是否需要重新启动应用?',
  13. success: (res) => {
  14. if (res.confirm) {
  15. uni.clearStorageSync() // 更新完成后刷新storage的数据
  16. updateManager.applyUpdate()
  17. }
  18. }
  19. })
  20. })
  21. updateManager.onUpdateFailed(() => {
  22. uni.showModal({
  23. title: '已有新版本上线',
  24. content: '小程序自动更新失败,请删除该小程序后重新搜索打开哟~~~',
  25. showCancel: false
  26. })
  27. })
  28. } else {
  29. if (useTip) {
  30. //没有更新
  31. uni.showToast({
  32. icon: 'none',
  33. title: '已经是最新版本!'
  34. })
  35. }
  36. }
  37. })
  38. } else {
  39. uni.showModal({
  40. title: '提示',
  41. content: '当前微信版本过低,无法使用该功能,请更新到最新的微信后再重试。',
  42. showCancel: false
  43. })
  44. }
  45. }