Network

Improve this doc

$ ionic plugin add cordova-plugin-network-information

Repo: https://github.com/apache/cordova-plugin-network-information

Requires Cordova plugin: cordova-plugin-network-information. For more info, please see the Network plugin docs.

Supported platforms

Usage

import { Network } from 'ionic-native';

// watch network for a disconnect
let disconnectSubscription = Network.onDisconnect().subscribe(() => {
  console.log('network was disconnected :-(');
});

// stop disconnect watch
disconnectSubscription.unsubscribe();


// watch network for a connection
let connectSubscription = Network.onConnect().subscribe(() => {
  console.log('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 (Network.type === 'wifi') {
      console.log('we got a wifi connection, woohoo!');
    }
  }, 3000);
});

// stop connect watch
connectSubscription.unsubscribe();

Static Members

type

Connection type

Returns: string

downlinkMax

Downlink Max Speed

Returns: string

onchange()

Returns an observable to watch connection changes

Returns: Observable<any>

ontypechange()

Returns an observable to watch connection type changes

Returns: Observable<any>

onDisconnect()

Get notified when the device goes offline

Returns: Observable<any> Returns an observable.

onConnect()

Get notified when the device goes online

Returns: Observable<any> Returns an observable.

Advanced

The type property will return one of the following connection types: unknown, ethernet, wifi, 2g, 3g, 4g, cellular, none

API

Native

General