apache / cordova-plugin-network-information

Apache Cordova Network Information Plugin
https://cordova.apache.org/
Apache License 2.0
464 stars 321 forks source link

What exactly is triggering online/offline events? #134

Open rolinger opened 3 years ago

rolinger commented 3 years ago

What specifically is triggering the offline event?

What if a user is connected to wifi that has no internet? Or happens to be transitioning from Cell to Wifi....or transition between wifis. OR....the user connects to a wifi, but they must authenticate (guest internet) via a web url. In all these scenarios, the The wifi port is up...user is getting an IP address but can't get to the internet? What is being evaluated in a situation like this to determine if the user is actually online?

I have a very specific case where this has happened to a user and when launched my app went white screen. We could replicate this several times on iOS (like 1 out of every 10 times), but seemingly have never had a problem on Android (that I know of). The iOS user is def a rare case but I need to understand why this is happening so I can compensate for these scenario so my app doesn't hang on launch.

If the user loses internet while the app is launched then everything works fine.

Its only on app launch for iOS. I have document.addEventListener("online", function() {}) ; at the top of my deviceReady section and it should fire during this odd situation...but its not....and the app is hanging.

powysm commented 2 years ago

@rolinger did you manage to get anywhere with this. This sounds pretty much exactly what some iOS users are reporting on our app. The only way i can recreate similar is to be connected to a wifi point w/o internet access.

I was considering treating an ios device as disconnected on app start up until it has an online event that isn't of type unknown or none, or testing this value on a timer on startup.

rolinger commented 2 years ago

@powysm - We changed many things. In fact we completely rewrote how our app initializes, greatly simplifying it and eliminating almost all outside dependencies during start up. We use google's places/autocomplete for typing in city/town names - so this loads way before onDeviceReady() fires. If the google maps api fails to load, the call back is never called, thus something must be wrong with the internet connection. The onDeviceReady() function then looks to see if the a maps global variable is to true or false (online/offline). If true, carry on, if false, pop warning message to user and then do a deeper dive into finding out why. Since we moved to this method we have no more reports of "offline" app hanging on launch:

<script async defer 
      src="https://maps.googleapis.com/maps/api/js?key=api_key&amp;libraries=places&callback=mapsCallback" type="text/javascript">
</script>