updateManager.wx.ts 688 B

123456789101112131415161718192021222324252627282930
  1. export default () => {
  2. if (!wx.canIUse('getUpdateManager')) {
  3. return
  4. }
  5. const updateManager = wx.getUpdateManager()
  6. updateManager.onCheckForUpdate((res) => {
  7. // 请求完新版本信息的回调
  8. console.log('版本信息', res)
  9. })
  10. updateManager.onUpdateReady(() => {
  11. wx.showModal({
  12. title: '更新提示',
  13. content: '新版本已经准备好,是否重启应用?',
  14. success(res) {
  15. if (res.confirm) {
  16. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  17. updateManager.applyUpdate()
  18. }
  19. },
  20. })
  21. })
  22. updateManager.onUpdateFailed(() => {
  23. // 新版本下载失败
  24. })
  25. }