繁体   English   中英

带有网络电容器的 Ionic 4 和烤面包机无法离线运行 PWA 应用程序

[英]Ionic 4 and Toaster with Network Capacitor is not working PWA app offline

更新:我已经更新了 Ionic 4.6.2 (最新),它在离线模式下给出了以下异常。

Network status changed {connected: false, connectionType: "none"}connected: falseconnectionType: "none"__proto__: Object
bootstrap:145 GET http://localhost:8100/85.js net::ERR_INTERNET_DISCONNECTED
requireEnsure @ bootstrap:145
webpackAsyncContext @ .*\.entry\.js$ include: \.entry\.js$ exclude: \.system\.entry\.js$ namespace object:407
loadModule @ chunk-09ec7fc0.js:61
(anonymous) @ chunk-09ec7fc0.js:1468
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
initializeComponent @ chunk-09ec7fc0.js:1450
(anonymous) @ chunk-09ec7fc0.js:1604
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
(anonymous) @ zone.js:889
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
onScheduleTask @ zone.js:301
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:404
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
resolvePromise @ zone.js:825
(anonymous) @ zone.js:741
Promise.then (async)
(anonymous) @ zone.js:1092
ZoneAwarePromise @ zone.js:910
Ctor.then @ zone.js:1091
createOverlay @ chunk-d83bfeae.js:30
create @ chunk-d83bfeae.js:8
push../node_modules/@ionic/angular/dist/fesm5.js.OverlayBaseController.create @ fesm5.js:4874
(anonymous) @ show-toast.service.ts:13
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
push../src/app/services/utilities/show-toast.service.ts.ShowToastService.showNetworkStateErrorToast @ show-toast.service.ts:12
(anonymous) @ network-state-service.ts:40
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
onInvokeTask @ core.js:17290
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:422
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498
invokeTask @ zone.js:1744
globalZoneAwareCallback @ zone.js:1770
zone.js:682 Unhandled Promise rejection: Cannot read property 'isProxied' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'isProxied' of undefined
    at chunk-09ec7fc0.js:1476
    at step (tslib.es6.js:99)
    at Object.next (tslib.es6.js:80)
    at fulfilled (tslib.es6.js:70)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at zone.js:889
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601) TypeError: Cannot read property 'isProxied' of undefined
    at http://localhost:8100/vendor.js:87541:27
    at step (http://localhost:8100/vendor.js:112070:23)
    at Object.next (http://localhost:8100/vendor.js:112051:53)
    at fulfilled (http://localhost:8100/vendor.js:112041:58)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:8100/polyfills.js:2753:26)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost:8100/polyfills.js:2512:43)
    at http://localhost:8100/polyfills.js:3251:34
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:2785:31)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:8100/polyfills.js:2557:47)
    at drainMicroTaskQueue (http://localhost:8100/polyfills.js:2963:35)

如何在 Ionic 4 中使用网络电容 当我进行调试时,我可以正确地看到执行。 但是toast不起作用。

我试过这个。 但它不起作用。

注意:实际上Network Capacitor工作正常。 但它没有显示toast 我已经在浏览器和 firebase 托管(即https )上测试了这个

服务.ts

 async WatchConnection() {
    this.networkListener = Network.addListener('networkStatusChange', (status) => {
      this.networkStatus = status;
      if (!this.networkStatus.connected) {
        this.showToastService.showNetworkStateErrorToast('Your internet seems to be down! Please check your network settings!');
      } else {
        setTimeout(() => {
          this.showToastService.toast.dismiss();
          if (this.networkStatus.connected) {
            this.showToastService.showNetworkStateSuccessToast('Internet connection available!');
          }
        }, 3000);
      }
    });

    this.networkStatus = await Network.getStatus();
  }

app.component.ts

 async initializeApp() {
    this.networkStateService.WatchConnection();
  }

我发现了一个黑客,直到 Ionic 团队解决这个问题。

吐司服务内部:

 constructor(private toastCtrl: ToastController, ) {
    this.toastCtrl.create({ animated: false }).then(t => { t.present(); t.dismiss(); });
  }

如果这对任何人有帮助,我对Angular Serviceworker也有同样的问题。 我切换到Workbox并且这个问题得到了解决,当然我可以切换到 workbox 因为我是从头开始开发应用程序并且没有任何生产

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM