Git Product home page Git Product logo

react-native-network-info's Introduction

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

Automatic Install

react-native link

Manual Install

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:

    include ':react-native-network-info'
    project(':react-native-network-info').projectDir = new File(settingsDir, '../node_modules/react-native-network-info/android')
  2. Update the android build tools version to 2.2.+ in android/build.gradle:

    buildscript {
        ...
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version
        }
        ...
    }
    ...
  3. Update the gradle version to 2.14.1 in android/gradle/wrapper/gradle-wrapper.properties:

    ...
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
    
  4. Add the compile line to the dependencies in android/app/build.gradle:

    dependencies {
        ...
        compile project(':react-native-network-info')
    }
  5. Add the import and link the package in MainApplication.java:

    import com.pusherman.networkinfo.RNNetworkInfoPackage; // <-- add this import
    
    public class MainApplication extends Application implements ReactApplication {
        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new RNNetworkInfoPackage() // <-- add this line
            );
        }
    }

Usage

import { NetworkInfo } from 'react-native-network-info';

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

// Get IPv4 IP (Android Only)
NetworkInfo.getIPV4Address(ipv4 => {
  console.log(ipv4);
});

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

// Get BSSID
NetworkInfo.getBSSID(ssid => {
  console.log(ssid);
});

Dev Notes

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

react-native-network-info's People

Contributors

chirag04 avatar davidstoneham avatar dylanvann avatar indraastra avatar jacob-meacham avatar jgfidelis avatar keeth avatar npomfret avatar pusherman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.