0

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);
    });
  };
NKurzweil
  • 3
  • 3

2 Answers2

0

You do not have added "then" in your code .Try this

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

    NetworkInfo.getGatewayIPAddress().then(gateway => {
     console.log(gateway);
    });
  };
Mehran Khan
  • 3,616
  • 1
  • 13
  • 10
  • As I wrote: I already tried it this way (and tried it again right now). I still get exactly the same warning and nothing returned by the function. – NKurzweil Oct 25 '20 at 09:59
0

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.

nazmul
  • 367
  • 2
  • 14
  • I am using expo, how can I get to those settings there? (and I am testing on Android, so I will follow the steps for manual linking for android) – NKurzweil Oct 25 '20 at 20:51
  • it was actually probably something with linking, becauso without using expo it works! – NKurzweil Nov 20 '20 at 12:20