Simple API that answers whether you are connected to the internet or not
_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.
There is only one API, the isConnected() function returning a promise.
``js
import HasInternet from 'react-native-has-internet';
HasInternet.isConnected().then((isConnected) => {
console.log('Do we have internet connection? ' + isConnected ? 'yes!' : 'no');
});
`
Supports only React Native 0.60 or higher.
- 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:
`xml
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
...
``
Nothing special to do. It should just work.