Ionic Native - Network in Browser


#1

I’m wondering how you would use the Native APIs like Network while still supporting ionic serve for development?

For example, I rely on Network plugin to determine connection state, e.g. to load a google places autocomplete and show an availability message. I expected that the native APIs would somehow handle the ionic serve scenario and only use cordova when available. Do I really neet to add “isBrowser” checks manually?

Greetings


#2

I too am wondering this. Ionic serve doesn’t work for me because my app has several HTTP requests


#3

I use this code to check whether i’m on device or using browser:

this.onDevice = this.platform.is(‘cordova’);
if (this.onDevice) { // using actual device
/* check the network connection using native cordova network plugin /
if (Network.connection !== “unknown” && Network.connection !== “none”)
this.online = true;
else this.online = false; // initial connection status
} else { // using browser
/
check the network connection using HTML5 API */
this.online = navigator.onLine;
}

seems to be working Ok, dunnno if that’s the right way tho.

-tmu