update.ts 633 B

12345678910111213141516171819
  1. const updateManager = wx.getUpdateManager();
  2. const env = wx.getAccountInfoSync().miniProgram.envVersion;
  3. export function appUpdate(force = false) {
  4. if (env !== wx.getStorageSync('env')) wx.clearStorageSync();
  5. wx.setStorageSync('env', env);
  6. updateManager.onUpdateReady(function () {
  7. wx.showModal({
  8. title: '更新提示',
  9. content: '新版本已经准备好,是否重启应用?',
  10. showCancel: !force,
  11. success(res) {
  12. if (res.confirm) {
  13. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  14. updateManager.applyUpdate()
  15. }
  16. }
  17. })
  18. })
  19. }