How to check if there is internet connection on app load

How to check if there is internet connection on app load. I tried onDisconnect and onConnect only works if we connect or disconnect while we are in the middle of running the app.

I even tried this -----

 if(!this.network.type){
        let alert = this.alertCtrl.create({
          title: 'No network',
          message: 'Check your internet connection',
          buttons: [{
            text: "OK",
            handler: () => { this.platform.exitApp(); }
          }]
        })
        alert.present();
      }
1 Like

That’s pretty close to something I have that works:

constructor(private _net: Network) {}
isConnected(): boolean {
  let conntype = this._net.type;
  return conntype && conntype !== 'unknown' && conntype !== 'none';
}

Naturally, you have to make sure the platform is ready before trying this, and one very easy mistake to make here is to install @ionic-native/network but forget to install the actual cordova plugin.

1 Like

what is isConnected() in your solution

It’s simply a function he’s defined.

You would use it in place of:
if(!this.network.type){

becomes:
if(!this.isConnected())