iOS PWA: reg.update() beim Start + visibilitychange — SW by-v412
iOS prüft im Standalone-Modus nicht automatisch ob ein neuer SW vorliegt. reg.update() erzwingt die Prüfung beim App-Öffnen und beim Zurückkehren aus dem Hintergrund — der bestehende controllerchange→reload greift dann.
This commit is contained in:
parent
1400033862
commit
4353994c68
2 changed files with 16 additions and 4 deletions
|
|
@ -458,13 +458,25 @@
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' })
|
navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' })
|
||||||
.catch(err => console.log('SW Registration failed:', err));
|
.then(reg => {
|
||||||
|
// iOS PWA: Update sofort prüfen (Standalone-Modus prüft sonst nicht automatisch)
|
||||||
|
reg.update();
|
||||||
|
})
|
||||||
|
.catch(err => console.warn('SW Registration failed:', err));
|
||||||
});
|
});
|
||||||
// Wenn ein neuer SW die Kontrolle übernimmt (nach Update),
|
|
||||||
// Seite neu laden — sonst hat app.js neue Seiten-JS aber altes api.js im Speicher.
|
// iOS PWA: erneut prüfen wenn App aus dem Hintergrund kommt
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.visibilityState === 'visible') {
|
||||||
|
navigator.serviceWorker.getRegistration().then(reg => reg?.update());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wenn neuer SW die Kontrolle übernimmt → Seite neu laden
|
||||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
navigator.serviceWorker.addEventListener('message', e => {
|
navigator.serviceWorker.addEventListener('message', e => {
|
||||||
if (e.data?.type === 'CHECK_NEARBY_ALERTS') {
|
if (e.data?.type === 'CHECK_NEARBY_ALERTS') {
|
||||||
window.App?._checkNearbyAlerts?.();
|
window.App?._checkNearbyAlerts?.();
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Offline-Cache + Push Notifications + Tile-Cache
|
Offline-Cache + Push Notifications + Tile-Cache
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
const CACHE_VERSION = 'by-v411';
|
const CACHE_VERSION = 'by-v412';
|
||||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue