In my phonegap app, I first check whether the device was connected to the internet before running the code and before calling the API. is.
if (window.navigator.onLine == incorrect) {// error handling} else {// do stuff & amp; Call API}
This works perfectly, but if the device loses its connection and within 5 seconds or the page reloads, then when I get disconnected Even after the code releases and the API is called the device is no longer connected. If the page is reloaded after approximately 5 seconds then the error is removed as expected to deal with it
It seems that about 5% of lost to convert the connection to "offline" It took up to seconds I checked it again with offline events and it was only removed after 5 seconds.
document.addEventListener ("Offline", offline, incorrect); Function onoffline () {warning ("now offline"); }
Is there a way to lose or deactivate connections or something else?
If the problem is specifically with page status check on page load, then the network-info plugin Use and call the function after page load is completed:
function check connection () {var networkState = navigator.network.connection.type; Var state = {}; States [connection. Unknown] = false; States [connection. Ethernet] = true; States [connection. FII] = true; States [connection. CELL_2G] = true; States [connection. CELL_3G] = true; States [connection. CELL_4G] = true; States [connection. NONE] = False; Return state [networktate]; }
After use in the application Offline
and online
events work specifically deviceready
The event is removed as soon as the network-information plugin can return the connection status.
No comments:
Post a Comment