Angular Service Workers not work on iOS standalone mode

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am working on PWA with Ionic v4 and Angular PWA service workers. On app.component.ts have a injected service to check if updates are available on PWA and then download and reload.

When I open PWA with the browser the service works fine and If I deploy an update the service worker update the cached PWA and ‘auto-reload’ the page.

The problem comes with PWA/standalone mode, on iOS when the PWA is added to homescreen it not refreshes anymore even killing it with the task app list. Only If I shutdown the device and on again it refreshes the state of the app. On Android devices all works as expected on PWA mode.

This is my version checker service implemented with Angular service worker:

import {Injectable} from '@angular/core';
import {SwUpdate} from '@angular/service-worker';

@Injectable()
export class LogUpdateService {

    constructor(updates: SwUpdate) {
        console.warn('check')
        updates.available.subscribe(event => {
            console.log('current version is', event.current);
            console.log('available version is', event.available);
            updates.activateUpdate().then(() => {
                console.warn('downloaded')
                document.location.reload();
            });
        });
        updates.activated.subscribe(event => {
            console.log('old version was', event.previous);
            console.log('new version is', event.current);
        });
    }
}

This is my package.json:

"dependencies": {
    "@angular/common": "^7.2.9",
    "@angular/core": "^7.2.9",
    "@angular/forms": "^7.2.9",
    "@angular/http": "^7.2.9",
    "@angular/platform-browser": "^7.2.9",
    "@angular/platform-browser-dynamic": "^7.2.9",
    "@angular/pwa": "0.13.8",
    "@angular/router": "^7.2.9",
    "@angular/service-worker": "7.2.12",
    "@ionic-native/core": "^5.2.0",
    "@ionic-native/network": "^5.2.0",
    "@ionic-native/splash-screen": "^5.2.0",
    "@ionic-native/status-bar": "^5.2.0",
    "@ionic/angular": "4.2.0",
    "@ionic/storage": "^2.2.0",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "cordova-plugin-network-information": "2.0.1",
    "cordova-sqlite-storage": "3.2.0",
    "core-js": "^2.6.5",
    "ionic2-calendar": "^0.5.2",
    "moment": "^2.24.0",
    "rxjs": "~6.4.0",
    "serve": "^10.1.2",
    "zone.js": "~0.8.29"
  },
  
                                                
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.