@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>
Listen for changes in the network connection.
Param | Type |
---|---|
eventName | 'networkStatusChange' |
listenerFunc | ConnectionStatusChangeListener |
Returns: Promise<PluginListenerHandle>
Since: 1.0.0
removeAllListeners()
removeAllListeners() => Promise<void>
Remove all listeners (including the network status changes) for this plugin.
Since: 1.0.0