question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS device]: isInternetReachable always returns null from addEventListener

See original GitHub issue

Environment

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:open
  • Created 2 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rassemdevcommented, Dec 15, 2021

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

import NetInfo from "@react-native-community/netinfo";
NetInfo.fetch().then(internetState => {
  console.log(internetState);
  if (internetState.isConnected && internetState.isInternetReachable) {
  }else{
  }
});

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?

0reactions
rassemdevcommented, Jan 18, 2022

on first attempt it is returning this, with isInternetReachable is returning null

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found