Skip to content

React Native library for getting information about the devices network

License

Notifications You must be signed in to change notification settings

APSL/react-native-network-info

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-network-info

React Native library for getting information about the devices network

Usage

First you need to install react-native-network-info:

npm install react-native-network-info --save

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

In XCode, in the project navigator, select your project. Add the lib*.a from the network-info project to your project's Build Phases ➜ Link Binary With Libraries Click .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../React - mark both as recursive.

Run your project (Cmd+R)

Android

  • android/settings.gradle
...
include ':react-native-network-info'
project(':react-native-network-info').projectDir = new File(settingsDir, '../node_modules/react-native-network-info/android')
  • android/app/build.gradle
dependencies {
	...
	compile project(':react-native-network-info')
}
  • register module (in MainActivity.java)
...

import com.pusherman.networkinfo.RNNetworkInfoPackage; // <--- IMPORT

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
	...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);

        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new RNNetworkInfoPackage())      // <- ADD HERE
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

        mReactRootView.startReactApplication(mReactInstanceManager, "YourProject", null);

        setContentView(mReactRootView);
    }
}

Examples

// require module
var NetworkInfo = require('react-native-network-info');

// Get SSID
NetworkInfo.getSSID(ssid => {
  console.log(ssid);
});

// Get Local IP
NetworkInfo.getIPAddress(ip => {
  console.log(ip);
});

Dev Notes

Notes on how this package was made can be found here.

About

React Native library for getting information about the devices network

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 61.3%
  • Objective-C 34.3%
  • JavaScript 4.4%