Check that WIFI is turned on is React Native iOS app

2766 views ios
8

Do you know how it is possible to check that WIFI is turned on is React Native iOS app. Due to the aGPS on iOS devices, the WIFI must be turned on in order for our location sensitive app to be able to work effectively and we want to notify the user in cases it is turned off.

Any idea how to achieve this in a React Native app for iOS?

answered question

1 Answer

10

Use NetInfo to check if the device is connected to wifi/cellular in React Native.

NetInfo exposes info about online/offline status

NetInfo.getConnectionInfo().then((connectionInfo) => {
  console.log('Initial, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
});
function handleFirstConnectivityChange(connectionInfo) {
  console.log('First change, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
  NetInfo.removeEventListener(
    'connectionChange',
    handleFirstConnectivityChange
  );
}
NetInfo.addEventListener(
  'connectionChange',
  handleFirstConnectivityChange
);

For more please visit https://facebook.github.io/react-native/docs/netinfo

posted this

Have an answer?

JD

Please login first before posting an answer.