Open rmartin94 opened 4 years ago
Hello, I have the same problem, is there any solution ? I'm testing on android device.
Hi
I've got 2 remarks:
1) You seem to be using version 2.0.1 of this plugin
cordova-plugin-network-information 2.0.1 "Network Information"
First try to update to version 2.0.2. That is the current version on npm.
2) In our company we do not rely on the 'offline' and 'online' events. In our project, we allways check the navigator.connection.type before every api call.
const networkState = navigator.connection.type; if (networkState === 'none') { console.log('We are offline'); } else { console.log('We are online'); }
Can any of these remarks help in solving your problem?
Kind regards, Pieter
Bug Report
Problem
What is expected to happen?
I would expect this plugin always to reflect the true network status of a mobile device, being notified when the status changes with its proper value
What does actually happen?
In general it works fine, but at some point I get stuck with a notification indicating that there's no network connection while the mobile device actual does have a connection. It's hard to reproduce, most time it works fine but on some occasions it doesn't. I subscribe to both onConnect and onDisconnect events.
This provides a really bad user experience since there are many web services that are not being called depending on the network status (some others are cached locally since I try to provide offline support and then sync to the server when connection is back online), like the login web service.
I'm not sure if I should rely entirely on this plugin anymore or if I'm doing something wrong. Does anyone had this behavior? I've seen it mostly on Android devices.
Thanks in advance!
Information
I subscribe to the provided events by the plugin on a service I use across the application, and when they are fired I check the network type just in case.... but to double check I set a timeout of 2 seconds and then re-check the current network type. Only then I change the status based on the type. If by some reason a subsequent event is fired I clear the timeout to prevent this with messing with the current network status from the last fired event
Command or Code
Environment, Platform, Device
I'm building an Ionic 4 application in Angular 7 with cordova
Version information
Checklist