updateManager.js 715 B

1234567891011121314151617181920212223242526272829
  1. export default () => {
  2. if (!wx.canIUse('getUpdateManager')) {
  3. return;
  4. }
  5. const updateManager = wx.getUpdateManager();
  6. updateManager.onCheckForUpdate(function (res) {
  7. // 请求完新版本信息的回调
  8. console.log('版本信息', res);
  9. });
  10. updateManager.onUpdateReady(function () {
  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(function () {
  23. // 新版本下载失败
  24. });
  25. };