Can you please explain how I can prompt the app user when a new version of my Ionic 4 PWA app is available?
Can you please explain how I can prompt the app user when a new version of my Ionic 4 PWA app is available?
Hello,
You can add the message and the code to check the current / available versions to the JS file and set its network strategy "network first" https://blog.appery.io/2019/06/some-u... to see the latest version message every time the user opens the app.
Please pay attention, you have to republish the app every time you change this version
Hi Serhii, thank you but there is no example of the code needed to accomplish this.
We are very sorry, but this is something outside the scope (https://docs.appery.io/docs/general-s...) of our standard support. I just said how it might be done with custom code.
You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about Advisory Pack (https://appery.io/services/#Advisory_...).
Really... I have to wait 2 days for this "outside the scope" reply
For the rest of the community, this is what I did. I'm sure it can be done better by some code ninja.
codeif ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js')
.then(registration => {
//console.log(registration);
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
Swal.fire({
title: "Notice",
icon: 'info',
html: "New content is available. Please refresh by closing and opening the app.",
confirmButtonText: 'Close',
confirmButtonColor: '#BFE222'
})
} else {
console.log('Content is cached for offline use.');
}
}
};
};
})
.catch(err => console.error('Error', err));
}/code