由于某种原因,如果我在Google Chrome中已经离线的PWA应用中重新加载页面,则Capacitor方法Network.getStatus()告诉我该页面处于在线状态。实际上,它将把连接状态更改触发3次,分别是“联机”,“脱机”和“联机”。当我将页面移回在线状态时,它仍然显示为在线状态,并且未触发任何事件。
如果我在线加载页面,然后将状态更改为离线,则页面会正确更新
constructor(
public storage: Storage,
private httpClient: HttpClient,
private sharedService: SharedService,
private loadingController: LoadingController) {
this.getStatus();
if (this.handler === undefined) {
this.handler = Network.addListener('networkStatusChange', (status) => {
console.log('Network status changed! ', status);
const oldStatus = this.status;
this.status = status;
if (this.status !== null && this.status.connected && !oldStatus.connected && oldStatus !== null) {
this.saveCachedData();
}
this.status = status;
if (!this.status.connected) {
this.sharedService.showNotification('Network connection has terminated.', 'danger', 5000);
} else {
try {
this.loaderElement.dismiss();
} catch (error) {
}
}
});
}
}
public async getStatus() {
this.status = await Network.getStatus();
}