5.0.0 • Published 4 years ago

react-native-has-internet v5.0.0

Weekly downloads
13
License
MIT
Repository
gitlab
Last release
4 years ago

React Native HasInternet

Simple JS API for React Native apps that answers whether you are connected to the internet or not. Works on both Android and iOS.

This library previously (in version 4) used to communicate with DNS service by Cloudfare and APNIC, wikipedia.org and ietf.org, but nowadays (version 5) it works via standard Android and iOS APIs for detecting internet presence.

On Android, we use ConnectivityManager and NetworkCapabilities.NET_CAPABILITY_VALIDATED.

On iOS, this library is just a thin wrapper around Reachability.

Usage

There is only one API, the isConnected() function returning a promise.

import HasInternet from 'react-native-has-internet';

HasInternet.isConnected().then((isConnected) => {
  console.log('Do we have internet connection? ' + isConnected ? 'yes!' : 'no');
});

Installation

Supports only React Native 0.60 or higher.

Android

  • Run npm install react-native-has-internet --save to install using npm.

  • Edit android/app/src/main/AndroidManifest.xml and add the annoated lines as below:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.reactnativeproject">

    <uses-permission android:name="android.permission.INTERNET" />   <!-- <- Add this line -->

    <application
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">

    ...
</manifest>

iOS

Nothing special to do. It should just work.

5.0.0

4 years ago

5.0.0-rc3

4 years ago

5.0.0-rc4

4 years ago

5.0.0-rc0

4 years ago

5.0.0-rc1

4 years ago

5.0.0-rc2

4 years ago

4.2.1

4 years ago

4.2.0

5 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago