Events 绑定更新PWA:swUpdate.isEnabled为true,但即使更改了ngsw-config.json,也不会调用订阅的方法

Events 绑定更新PWA:swUpdate.isEnabled为true,但即使更改了ngsw-config.json,也不会调用订阅的方法,events,service-worker,progressive-web-apps,angular-service-worker,Events,Service Worker,Progressive Web Apps,Angular Service Worker,服务/pwa.service.ts: import { Injectable } from '@angular/core'; import { SwUpdate } from '@angular/service-worker'; import {Observable} from "rxjs/Observable"; import "rxjs/add/observable/interval"; @Injectable() export class PwaService { public pr

服务/pwa.service.ts:

import { Injectable } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';
import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/interval";

@Injectable()
export class PwaService {
  public promptEvent: any;

  constructor(private swUpdate: SwUpdate) {
    alert('swUpdate isEnabled:' + swUpdate.isEnabled);// => alerts true
    if (swUpdate.isEnabled) {
      Observable.interval(10)
                .subscribe(() => swUpdate.checkForUpdate().then(() => alert('checking for swUpdate')));//<= Not triggered
    }
  }

  public checkForUpdates(): void {
    this.swUpdate.available.subscribe(event => this.promptUser());
  }

  private promptUser(): void {
    alert('updating to new version');//<=Not triggered either
    this.swUpdate.activateUpdate()
                .then(() => document.location.reload());
  }
}
app.modules.ts:

imports: [
....
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
]
providers: [
...
PwaService,
]
app.component.ts:

import { PwaService } from './services/pwa.service'; 
....
constructor(public Pwa: PwaService) {
  this.Pwa.checkForUpdates();
}
ngsw config.json(只是从
lazy
prefetch
的微小更改)来触发更新:

....
"installMode": "prefetch",
....

这在所有设备上都适用:

export class PwaUpdateService {

    updateSubscription;

    constructor(public updates: SwUpdate) {
    }

    public checkForUpdates(): void {
        this.updateSubscription = this.updates.available.subscribe(event => this.promptUser());

        if (this.updates.isEnabled) {
            // Required to enable updates on Windows and ios.
            this.updates.activateUpdate();

            interval(60 * 60 * 1000).subscribe(() => {
                this.updates.checkForUpdate().then(() => {
                    // console.log('checking for updates');
                });
            });

        }

        // Important: on Safari (ios) Heroku doesn't auto redirect links to their https which allows the installation of the pwa like usual
        // but it deactivates the swUpdate. So make sure to open your pwa on safari like so: https://example.com then (install/add to home)
    }

    promptUser(): void {
        this.updates.activateUpdate().then(() => {
            window.location.reload();
        });
    }
}

这在所有设备上都适用:

export class PwaUpdateService {

    updateSubscription;

    constructor(public updates: SwUpdate) {
    }

    public checkForUpdates(): void {
        this.updateSubscription = this.updates.available.subscribe(event => this.promptUser());

        if (this.updates.isEnabled) {
            // Required to enable updates on Windows and ios.
            this.updates.activateUpdate();

            interval(60 * 60 * 1000).subscribe(() => {
                this.updates.checkForUpdate().then(() => {
                    // console.log('checking for updates');
                });
            });

        }

        // Important: on Safari (ios) Heroku doesn't auto redirect links to their https which allows the installation of the pwa like usual
        // but it deactivates the swUpdate. So make sure to open your pwa on safari like so: https://example.com then (install/add to home)
    }

    promptUser(): void {
        this.updates.activateUpdate().then(() => {
            window.location.reload();
        });
    }
}

我猜你尝试过隐姓埋名并清除缓存的东西,还将服务器设置为不缓存文件?你的“网络”选项卡是什么样子的?我猜你是在检查ngsw.json,试图隐姓埋名,清除缓存的内容,并将服务器设置为不缓存文件?您的网络选项卡是什么样子的,检查ngsw.json,