The 2017 Ionic Developer Survey Results are in!

Network

Improve this doc

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

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

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-network-information
    $ npm install --save @ionic-native/network
    
  2. Add this plugin to your app's module

Supported platforms

Usage

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

constructor(private network: Network) { }

...

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

// stop disconnect watch
disconnectSubscription.unsubscribe();


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

// stop connect watch
connectSubscription.unsubscribe();

Instance Members

type

Connection type

Returns: string

downlinkMax

Downlink Max Speed

Returns: string

onchange()

Returns an observable to watch connection 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