Ionic Network don't return any data or response

I am trying to check the internet/network connection of the device using Network Plugin but it doesn't seem to work. It didn't even return any data or error messages on the console. Here is my code.

import { Network } from '@ionic-native/network';

@Component({
templateUrl: ‘app.html’
})

export class MyApp {

constructor(public platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar
public network: Network) {
this.initializeApp();
}

initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.checkInternetConnection();
}
}

checkInternetConnection() {
this.network.onDisconnect().subscribe(data => {
console.log(‘network was disconnected :-(’);
}, error => console.log(error));

this.network.onConnect().subscribe(data => {
  console.log('network connected!');
  setTimeout(() => {
    console.log('woohoo!');
  }, 3000);
}, error => console.log(error));

}
}

I hope someone can help me. Thank you in advance 😊

#ionic #cordova

5 Likes4.60 GEEK