๐ง NetInfo
Removed. Use react-native-community/react-native-netinfo instead.
NetInfo exposes info about online/offline status
#
ConnectionType enumConnectionType
describes the type of connection the device is using to communicate with the network.
Cross platform values for ConnectionType
:
none
- device is offlinewifi
- device is online and connected via wifi, or is the iOS simulatorcellular
- device is connected via Edge, 3G, WiMax, or LTEunknown
- error case and the network status is unknown
Android-only values for ConnectionType
:
bluetooth
- device is connected via Bluetoothethernet
- device is connected via Ethernetwimax
- device is connected via WiMAX
#
EffectiveConnectionType enumCross platform values for EffectiveConnectionType
:
2g
3g
4g
unknown
#
AndroidTo request network info, you need to add the following line to your app's AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
#
Methods#
Properties#
Reference#
MethodsaddEventListener()
#
Adds an event handler.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
eventName | enum(connectionChange, change) | Yes | The change event name. |
handler | function | Yes | Listener function. |
Supported events:
connectionChange
: Fires when the network status changes. The argument to the event handler is an object with keys:type
: AConnectionType
(listed above)effectiveType
: AnEffectiveConnectionType
(listed above)
change
: This event is deprecated. Listen toconnectionChange
instead. Fires when the network status changes. The argument to the event handler is one of the deprecated connectivity types listed above.
removeEventListener()
#
Removes the listener for network status changes.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
eventName | enum(connectionChange, change) | Yes | The change event name. |
handler | function | Yes | Listener function. |
getConnectionInfo()
#
Returns a promise that resolves to an object with type
and effectiveType
keys whose values are a ConnectionType
and an EffectiveConnectionType
), respectively.
isConnectionExpensive()
#
Available on Android. Detect if the current active connection is metered or not. A network is classified as metered when the user is sensitive to heavy data usage on that connection due to monetary costs, data limitations or battery/performance issues.
#
PropertiesisConnected
#
Available on all platforms. Asynchronously fetch a boolean to determine internet connectivity.