Page 1 of 1

How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Tue Apr 07, 2020 1:19 pm
by Dupdroid

Can you please explain how I can prompt the app user when a new version of my Ionic 4 PWA app is available?


How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Thu Apr 09, 2020 11:46 am
by Serhii Kulibaba

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


How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Thu Apr 09, 2020 12:31 pm
by Dupdroid

Hi Serhii, thank you but there is no example of the code needed to accomplish this.


How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Thu Apr 09, 2020 1:43 pm
by Serhii Kulibaba

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_...).


How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Thu Apr 09, 2020 3:05 pm
by Dupdroid

Really... I have to wait 2 days for this "outside the scope" reply


How would I display a "new version available" message for a PWA inside my Ionic 4 app?

Posted: Thu Apr 09, 2020 3:09 pm
by Dupdroid

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