[iOS device]: isInternetReachable always returns null from addEventListener
See original GitHub issueEnvironment
System:
OS: macOS 11.4
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.4.2 - ~/.nvm/versions/node/v16.4.2/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v16.4.2/bin/yarn
npm: 7.18.1 - ~/.nvm/versions/node/v16.4.2/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.64.1 => 0.64.1
react-native-macos: Not Found
Platforms
iOS
Versions
- iOS: 14.5
- react-native-netinfo: “6.0.0”,
- react-native: 64.1
- react: 17.0.1
Description
NetInfo does not return an isInternetReachable when using the addEventListener implementation of NetInfo. For example:
NetInfo.addEventListener((state: NetInfoState) => {
console.log(state.isInternetReachable); // will always return null
});
however:
const { isInternetReachable } = useNetInfo(); // returns the expected state
the hook works correctly
Reproducible Demo
I am able to reproduce this 100% reliably on all my iOS devices as well as seeing this result in production.
Note
other properties from the NetInfoState are reported accurately
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top Results From Across the Web
The key isInternetReachable is always returning false for a ...
The key isInternetReachable is always returning false for a minute in iOS whenever the app comes to foreground from background in react-native.
Read more >How to Handle Network Connection in Your React Native App
isInternetReachable — A Boolean value that determines whether or not the internet can be accessed using the current connection. isWifiEnabled ( ...
Read more >Fixing “Cannot read property 'addEventListener' of null” Error ...
In this article, we will be discussing in detail why the “Cannot read property 'addEventListener' of null” is encountered and different ways ...
Read more >Managing network connection status in React Native
Then, run the following command for iOS for linking libraries using ... The addEventListener() method will return the reference to the ...
Read more >NetInfo - React Native
Cross platform values for ConnectionType : none - device is offline; wifi - device is online and connected via wifi, or is the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On my app, in a on click event, i am trying to get some data from api. Before that i am checking internet connectivity. When i’m using this
on first attempt it is returning this, with isInternetReachable is returning null.
LOG {"details": {"bssid": null, "ipAddress": "192.168.1.2", "isConnectionExpensive": false, "ssid": null, "subnet": "255.255.255.0"}, "isConnected": true, "isInternetReachable": null, "type": "wifi"}
but if i click the button again, now isInternetReachable is returning true
LOG {"details": {"bssid": null, "ipAddress": "192.168.1.2", "isConnectionExpensive": false, "ssid": null, "subnet": "255.255.255.0"}, "isConnected": true, "isInternetReachable": true, "type": "wifi"}
Its only happening on ios. any idea guys?
@mikehardy here is an expo of my project, run this with ios. then check the log, on first attempt of onclick even isInternetReachable is returning null, Can you give me an example/snack of your approach?