React Native library for getting information about the devices network
React Native library for getting information about the devices network
React Native library for getting information about the devices network
Version 3+ requires RN 0.47 or higher Version 2+ requires RN 0.40 - RN 0.46
npm install react-native-network-info --saveor
yarn add react-native-network-infoLinking the package manually is not required anymore with Autolinking.
iOS also requires CocoaPods install$ cd ios && pod install && cd ..
console.log(ipAddress); });
// Get IPv4 IP (priority: WiFi first, cellular second) NetworkInfo.getIPV4Address().then(ipv4Address => { console.log(ipv4Address); });
// Get Broadcast NetworkInfo.getBroadcast().then(broadcast => { console.log(broadcast); });
// Get SSID NetworkInfo.getSSID().then(ssid => { console.log(ssid); });
// Get BSSID NetworkInfo.getBSSID().then(bssid => { console.log(bssid); });
// Get Subnet NetworkInfo.getSubnet().then(subnet => { console.log(subnet); });
// Get Default Gateway IP NetworkInfo.getGatewayIPAddress().then(defaultGateway => { console.log(defaultGateway); });
// Get frequency (supported only for Android) NetworkInfo.getFrequency().then(frequency => { console.log(frequency); });
### Manually Linking the Library
If `react-native link` fails and you are not using the auto linking provided in React Native >= 0.60
### `iOS`
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
2. Go to node_modules ➜ react-native-network-info and add the .xcodeproj file
3. Add `RNNetworkInfo.a` to `Build Phases -> Link Binary With Libraries`
Run your project (Cmd+R)
### `Android`
1. Add the following lines to `android/settings.gradle`:
```gradle
include ':react-native-network-info'
project(':react-native-network-info').projectDir = new File(settingsDir, '../node_modules/react-native-network-info/android')2.2.+ in android/build.gradle:buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.2.+' // getPackages() {
return Arrays.asList(
new MainReactPackage(),
new RNNetworkInfoPackage() // <-- add this line
);
}
}Notes on how this package was made can be found here.
No open issues yet, or sync has not completed.