Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49316

Network state not getting in Ionic 4

$
0
0

@OmDIonic wrote:

Hi All
For checking internet in app I implemented below code but nothing is triggering

Plugin Installation:
ionic cordova plugin add cordova-plugin-network-information
npm install @ionic-native/network
Testing Enviornment : ios simulator iphone xs 12.1 . (cant test on real device to unavailability )
Internet connection to simulator : WIFI connection in MacBook

Code:

        this.platform.ready().then(() => {
          if (this.platform.is('ios')) {

             // watch network for a disconnection
          let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
            alert('network was disconnected :-(');
          });
          
          // stop disconnect watch
          disconnectSubscription.unsubscribe();
          
  
                // watch network for a connection
          let connectSubscription = this.network.onConnect().subscribe(() => {
            alert('network connected!');
            // We just got a connection but we need to wait briefly
             // before we determine the connection type. Might need to wait.
            // prior to doing any api requests as well.
            setTimeout(() => {
              if (this.network.type === 'wifi') {
                alert('we got a wifi connection, woohoo!');
              }
            }, 3000);
          });
          
          // stop connect watch
          connectSubscription.unsubscribe();
     
          }
    });

Can somebody tell me my mistake?.
Thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>