Ionic Structure - Internet Connection Detection

I am developing a simple application using the Ionic framework (and AngularJs) that fetches json data from my web page. How can I detect if there is an "Internet connection" and display a message to the user: "Connect to the Internet" if not.

EDIT

Can I use the cordova API to do this?

+3


source to share


2 answers


Cordova provides a plugin org.apache.cordova.network-information

.

See documentation



This plugin provides an implementation of the old version of the Network Information API. It provides information about the cellular and wireless connection of the device and whether the device has an Internet connection.

+5


source


If I'm not mistaken, this plugin only detects if Wi-Fi or cellular is enabled on the device. This does not always mean that the application can actually reach your remote server if you are connected to a WiFi network without an Internet connection. So the only solution I have found to allow the application to access the remote server is to ping the server all the time.



+3


source







All Articles