IONIC native Network.onDisconnect() running code twice

Hi All !
i am working with ionic 2 RC1 and using sublime as text editor. i need to check if the network connection is connected or not. so for this purpose i am using ionic native Network for this purpose. but i am facing problem with the Network.onDisconnect() Observable. I have edited initializeApp() method in which i check for network connection and show alert if connection got disconnected. the I have the following code written in app.component.ts

  showAlert(title, msg) {
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: msg,
      buttons: ['OK']
    });
    alert.present();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      let disconnectSubscription = Network.onDisconnect().subscribe(() => {
        this.showAlert("Error", "No internet connection");
      });
      StatusBar.styleDefault();
    });
  }

The problem i am facing is that alert is shown twice if application get disconnected from internet. I have found similar issue in this post but it got unanswered. Any help on this regard will be much appreciated.
Thanks in advance :slight_smile:

I am still facing the same issue… it fires twice

hi there, any updates on this ?

hi @yasirpanjsheri. I have also posted that question on Stackoverflow and sebaferreras sugessted a workaround. you can see that solution, but proper solution is not yet found.

1 Like

you refer that link : https://stackoverflow.com/questions/42414277/ionic-2-native-network-ondisconnect-running-code-twice

1 Like