- React Native Bridge to check if device is able to access internet, since React Native NetInfo doesn't check if the user can access the internet, it only checks if the device is connected to a network
$ npm install react-native-connection-status --save
$ react-native link react-native-connection-status
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNConnectionStatusPackage;
to the imports at the top of the file - Add
new RNConnectionStatusPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-connection-status' project(':react-native-connection-status').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-connection-status/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-connection-status')
-
In XCode, right-click the Libraries folder under your project ➜
Add Files to <your project>
-
Go to node_modules ➜ react-native-connection-status ➜ ios and add the
RNConnectionStatus.xcodeproj
file -
Go to your apps project settings ➜ "Build Phases" ➜ "Link Binary With Libraries" and add
libRNConnectionStatus.a
from the linked project
import { hasInternetConnection } from 'react-native-connection-status';
hasInternetConnection((isConnected: boolean) => console.log(isConnected))