react-native-netinfo library not working

##System Environment:
OS: Windows 10 OS 64 bit
CPU: Intel core i7-9700k @ 3.60GHz
Memory: 550.87 MB / 16.00 GB

Installation Logs :

PS E:\React Native Projects\vMobile-react-project\vMobile-react-project> npm install --save @react-native-community/netinfo
npm WARN expo-battery@1.0.1 requires a peer of @unimodules/core@~1.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})

  • @react-native-community/netinfo@5.0.0
    updated 1 package and audited 37753 packages in 4.585s
    found 15 low severity vulnerabilities
    run npm audit fix to fix them, or npm audit for details

Platforms

Issue related to both Android and IOS

Versions

  • Android: 9
  • iOS: 13.1.3
  • react-native-netinfo: 5.0.0
  • react-native: 0.59.8
    expo: 35.0.0

Description

In my expo project i need details like ssid , ipAddress of WiFi to which current phone is connected.
i followed below procedure as follows :

first step i did npm install --save @react-native-community/netinfo
second step i imported NetInfo from “@react-native-community/netinfo”;
third step i wrote below code
NetInfo.fetch().then(state => {
console.log(“Connection type”, state.type);
console.log(“Is connected?”, state.isConnected);
console.log("Details ", state.detail);
});

following is the output i can see on my terminal

Connection type wifi
Is connected? true
Details Object {
“isConnectionExpensive”: false,
}

So if you see in output Details i get only isConnectionExpensive but not ssid and ipAddress. This is happening on both Android and IOS devices. As i am newbie to react native i don’t understand where did i do mistake because of which i am not getting wiFi ssid and ipaddress. Please give me a solution for the above mentioned problem.

I get the same as you with SDK version 35, but it works for me on SDK 36 (tested on an Android phone).

1 Like

Hi, Thanks for your reply.
Yes you are correct now it’s working when i updated my SDK to 36 but only in android phones. But for iOS its still showing null like below

Connection type wifi

Is connected? true

Detail? Object {
“ipAddress”: “192.168.0.175”,
“isConnectionExpensive”: false,
“ssid”: null,
“subnet”: “255.255.255.0”,
}

I have tested this in iOS 12.4 and 13.3. Can you please guide me. Thanks

hmmm… I’ve found some posts that seem relevant:


So it seems that you might have to get “Location” permissions for this to work on iOS. I’m not quite sure how the “entitlements” mentioned in the other link fit in with a managed Expo app.

Yes incase of iOS i have allowed location permission but still its giving ssid null. can you please check in iOS. Thanks

Sorry, I don’t have access to an IOS device at the moment, but I tried the iOS preview on snack and I also got null for the SSID.

1 Like

hmm…any alternate method you know for this problem…becuase i dont want to eject Expo.

Sorry, I don’t know any more than you. Hopefully someone else here might be able to offer some advice. Otherwise it might be worth googling for solutions or asking on StackOverflow.

It might just be a matter of some sort of permissions, so hopefully you will not need to eject.

@adamjnav @nikki @thetc Please help me on this problem.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.