How to upgrade a meteor app

孤街浪徒 提交于 2019-12-25 18:19:26

问题


My App created by Meteor is now doing upgrading by Meteor's HCP(Hot Code Push), which means the user will get a new version as soon as he restarts the App, without any information or confirm dialog.

HCP is great, but there are two reasons some users don't want the App be upgraded quietly:

  1. New version may have degrades or other risks.
  2. Old version is enough for theirs uses.

So I want to know if there is a way, I can show user a new-version-available dialog describing features of the new version, and ask him whether to upgrade or not. When he agreed, use HCP to do the upgrade work or, download the necessary package by writing code if HCP not usable in this occasion.

By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

Many thanks in advance for answering any one of the two questions, or both. Thank you.


回答1:


By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

HCP should work on all platforms in the same way.

To show prompt dialog you have to intercept HCP in Reload._onMigrate hook:

import { Reload } from 'meteor/reload';

Reload._onMigrate(() => {
  const decision = confirm("New version is available, would you like to upgrade now?")
  return [decision]; // Return [false] to manually handle HCP
});

This is a very simple example, you can trigger nice UI/UX element to handle it.

For example we always return [false] in _onMigrate hook. Show to the user nice pop-up. And if user choose to update now, we trigger next function (pick options you need):

// Purge and reload cache for AppCache package
window.applicationCache.swapCache();
window.applicationCache.update();

// Drop ServiceWorker cache
window.caches.keys().then((keys) => {
  keys.forEach((name) => {
    window.caches.delete(name);
  });
}).catch((err) => {
  console.error('window.caches.delete', err);
});

// Unregister Service Worker
SWRegistration.unregister();

// Reload the page
if (window.location.hash || window.location.href.endsWith("#")) {
  window.location.reload();
} else {
  window.location.replace(window.location.href);
}


来源:https://stackoverflow.com/questions/44695207/how-to-upgrade-a-meteor-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!