Skip to main content
Version: v5

@capacitor/network

The Network API provides network and connectivity information.

Installโ€‹

npm install @capacitor/network
npx cap sync

Exampleโ€‹

import { Network } from '@capacitor/network';

Network.addListener('networkStatusChange', status => {
console.log('Network status changed', status);
});

const logCurrentNetworkStatus = async () => {
const status = await Network.getStatus();

console.log('Network status:', status);
};

APIโ€‹

getStatus()โ€‹

getStatus() => Promise<ConnectionStatus>

Query the current status of the network connection.

Returns:

Promise<ConnectionStatus>

Since: 1.0.0


addListener('networkStatusChange', ...)โ€‹

addListener(eventName: 'networkStatusChange', listenerFunc: ConnectionStatusChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for changes in the network connection.

ParamType
eventName'networkStatusChange'
listenerFunc
ConnectionStatusChangeListener

Returns:

Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


removeAllListeners()โ€‹

removeAllListeners() => Promise<void>

Remove all listeners (including the network status changes) for this plugin.

Since: 1.0.0


Interfacesโ€‹

ConnectionStatusโ€‹

Represents the state and type of the network connection.

PropTypeDescriptionSince
connectedbooleanWhether there is an active connection or not.1.0.0
connectionType
ConnectionType
The type of network connection currently in use. If there is no active network connection, connectionType will be 'none'.1.0.0

PluginListenerHandleโ€‹

PropType
remove() => Promise<void>

Type Aliasesโ€‹

ConnectionTypeโ€‹

The type of network connection that a device might have.

'wifi' | 'cellular' | 'none' | 'unknown'

ConnectionStatusChangeListenerโ€‹

Callback to receive the status change notifications.

(status: ConnectionStatus): void