Search code examples
react-nativeunhandled-promise-rejection

react-native-network-info 'null is not an object'


It does not matter which function of the react-native-network-info I use, I always get a warning ([Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNNetworkInfo.getGatewayIPAddress')]) and the function does not return anything. See code sample. I also already tried to do it exactly as in the documentation (https://www.npmjs.com/package/react-native-network-info):

// Get Default Gateway IP
NetworkInfo.getGatewayIPAddress().then(defaultGateway => {
  console.log(defaultGateway);
});
import { NetworkInfo } from "react-native-network-info";

 _updateStates = () => {
    ...
    ...

    NetworkInfo.getGatewayIPAddress((gateway) => {
      console.log(gateway);
    });
  };

Solution

  • It seems , autolinking does not work properly for this library, i had to follow the following steps to make it work , enter image description here

    It's noted in the documentation of the library for manual setup. But don't follow the 3rd step , otherwise your ios project won't build. I tried the following method from the library ,

    NetworkInfo.getIPAddress().then((ipAddress) => {
          console.log(ipAddress);
        });
    

    and it worked.