How To Upgrade A Meteor App
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
Solution 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 packagewindow.applicationCache.swapCache();
window.applicationCache.update();
// Drop ServiceWorker cachewindow.caches.keys().then((keys) => {
keys.forEach((name) => {
window.caches.delete(name);
});
}).catch((err) => {
console.error('window.caches.delete', err);
});
// Unregister Service WorkerSWRegistration.unregister();
// Reload the pageif (window.location.hash || window.location.href.endsWith("#")) {
window.location.reload();
} else {
window.location.replace(window.location.href);
}
Post a Comment for "How To Upgrade A Meteor App"