# OnDisconnect() firing twice alert

**URL:** <https://forum.ionicframework.com/t/ondisconnect-firing-twice-alert/110571>\
**Category:** ionic-v3\
**Created:** [October 31, 2017, 12:44pm UTC](https://forum.ionicframework.com/t/ondisconnect-firing-twice-alert/110571 "2017-10-31T12:44:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharanagouda](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sharanagouda](https://forum.ionicframework.com/u/Sharanagouda)\
**Post date:** [October 31, 2017, 12:44pm UTC](https://forum.ionicframework.com/t/ondisconnect-firing-twice-alert/110571/1 "2017-10-31T12:44:50Z")

</div>

Hi All… Have you tried Network status  
steps which I followed using Ionic 2 to know whether you are online or offline

1. install

$ ionic cordova plugin add cordova-plugin-network-information  
$ npm install --save @ionic-native/network

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

constructor( private network: Network ){

       let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
               this.events.publish('network:online', false);
               this.online = false;
         
           console.log('network was disconnected :-(');

           let alert = this.alertCtrl.create({
               title: 'Network was disconnected :-(',
               subTitle: 'Please check your connection. And try again',
               buttons: ['OK']
           });
           alert.present();
       });
}

```

It firing twice Is anyone have solution for this and onConnect() is firing one time only  
and I have checked this website

[Ionic network doc](https://ionicframework.com/docs/native/network/)  
[ampersandacademy](https://ampersandacademy.com/tutorials/materialize-css/ionic-2-framework-network-information-plugin-connectd-disconnected)  
[stackoverflow](https://stackoverflow.com/questions/42414277/ionic-2-native-network-ondisconnect-running-code-twice)  
[Ionic forum](https://forum.ionicframework.com/t/online-and-offline-event-are-firing-2-times-in-a-row/15839)  
[github](https://github.com/ionic-team/ionic-native/issues/1036)

Please give me a solution if u solved means and I have ref websites please don’t suggest which I have already mentioned.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![wthijmen](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wthijmen/32/113686_2.png) [@wthijmen](https://forum.ionicframework.com/u/wthijmen)\
**Post date:** [October 31, 2017, 1:37pm UTC](https://forum.ionicframework.com/t/ondisconnect-firing-twice-alert/110571/2 "2017-10-31T13:37:07Z")

</div>

Why are you not making a custom call for checking if the network is online?  
Just simply create a provider instance for it.  
In this provider you got the following sample code:

```auto
// -------------------------------------------------------------------------------------------------------------------------
    // @network
    // -------------------------------------------------------------------------------------------------------------------------
    // Check if the network is online/offline
    // -------------------------------------------------------------------------------------------------------------------------
    networkStatus()
    {
        var oHeaders = new Headers();
        oHeaders.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

        this.http.post('http://URL/network-status', {headers: oHeaders})
        .subscribe(oRes => {

            this.bOnline = true;

        }, (sError) => {

            this.bOnline = false;

        });
    }

```

Simply then return in your PHP function a `true`.  
Then you can check back in your provider if the network is online with a var named like bOnline (true/false) (b stands for Boolean).

Hope I helped.
