react-native-network-info
React Native library for getting information about the devices network
Requirements
Version 3+ requires RN 0.47 or higher Version 2+ requires RN 0.40 - RN 0.46
Installation
npm install react-native-network-info --save
or
yarn add react-native-network-info
Linking the library
Using React Native >= 0.60
Linking the package manually is not required anymore with Autolinking.
iOS
also requires CocoaPods install
$ cd ios && pod install && cd ..
Using React Native >= 0.60
react-native link react-native-network-info
Usage
; // Get Local IPNetworkInfo; // Get IPv4 IP (priority: WiFi first, cellular second)NetworkInfo; // Get BroadcastNetworkInfo; // Get SSIDNetworkInfo; // Get BSSIDNetworkInfo; // Get SubnetNetworkInfo; // Get Default Gateway IPNetworkInfo; // Get frequency (supported only for Android)NetworkInfo;
Manually Linking the Library
If react-native link
fails and you are not using the auto linking provided in React Native >= 0.60
iOS
-
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
-
Go to node_modules ➜ react-native-network-info and add the .xcodeproj file
-
Add
RNNetworkInfo.a
toBuild Phases -> Link Binary With Libraries
Run your project (Cmd+R)
Android
-
Add the following lines to
android/settings.gradle
:include ':react-native-network-info'project(':react-native-network-info').projectDir = new File(settingsDir, '../node_modules/react-native-network-info/android') -
Update the android build tools version to
2.2.+
inandroid/build.gradle
:buildscript {...dependencies {classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version}...}... -
Update the gradle version to
2.14.1
inandroid/gradle/wrapper/gradle-wrapper.properties
:... distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
-
Add the compile line to the dependencies in
android/app/build.gradle
:dependencies {...compile project(':react-native-network-info')} -
Add the import and link the package in
MainApplication.java
:// <-- add this import
Dev Notes
Notes on how this package was made can be found here.