【发布时间】:2022-08-17 05:00:57
【问题描述】:
我有一个带角度的离子 PWA。每个软件包都是最新版本。
我有一个 SwupdaterService 并且在生产模式下,应用程序总是像循环一样重新加载,没有任何更新。
这是我的服务:
export class SwupdaterService {
constructor(public updates: SwUpdate) {
if (updates.isEnabled) {
interval(6 * 60 * 60).subscribe(() => updates.checkForUpdate()
.then(() => console.log(\'checking for updates\')));
}
}
public checkForUpdates(): void {
this.updates.versionUpdates.subscribe(event => this.promptUser());
}
private promptUser(): void {
console.log(\'updating to new version\');
this.updates.activateUpdate().then((res) => {
alert(\'here!\');
document.location.reload()
});
}
}
在 app.module 我有这个:
ServiceWorkerModule.register(\'ngsw-worker.js\', {
enabled: environment.production,
// Register the ServiceWorker as soon as the application is stable
// or after 30 seconds (whichever comes first).
registrationStrategy: \'registerWhenStable:30000\'
}),
最后是我的 app.component:
export class AppComponent {
constructor(
private platform: Platform,
private sw: SwupdaterService,
private localizationService: LocalizationService) { }
async ngOnInit() {
await this.initializeApp();
}
async initializeApp() {
await this.platform.ready();
this.sw.checkForUpdates();
await this.localizationService.setInitialAppLanguage();
}
}
有人知道为什么会这样吗?