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.

NetInfo returns true when connected to [WiFi|cellular] but Internet is not reachable

See original GitHub issue

When I have mobile data on(cellular internet - device is connected via Edge, 3G, WiMax, or LTE) and my data package is finished (i.e: I cannot use internet) Netinfo always return true.

Environment

Environment: OS: macOS High Sierra 10.13.3 Node: 8.9.1 Yarn: Not Found npm: 5.6.0 Watchman: Not Found Xcode: Xcode 9.2 Build version 9C40b Android Studio: Not Found

Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.54 => 0.54

Expected Behavior

Ideally netinfo should return false when there is no internet connectivity. Just turning on the mobile data should not enough for it to depict that device has internet connection.

Actual Behavior

  NetInfo.isConnected.fetch().then(isConnected => {
     alert(isConnected);
   })

Steps to Reproduce

Just turn off the wifi and turn on the data connection on the mobile device which has no sim or with the sim which has no credit. It is happening on both iOS & Android.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
sfm2222commented, Mar 21, 2018

@hramos thank you.

I think most of the developers are not much concerned with the fact that device is either connected to wifi/cellular or not(leaving aside if you are keen about data package spent in certain scenerio), the major concern is to check the internet reachability, to limit the actions which should not performed by the app if there is no internet connection.

For the temporary solution I have just sent a ping request to my WebAPI through code before making a request if it’s not reachable so I assume there is no internet connection. Either this is incorrect WebAPI server could be down.

return fetch('URL')
      .then((response) => {
      })
  .catch((error) => {
        if(error == 'TypeError: Network request failed'){
          Alert.alert('Something went wrong', 'Kindly check if the device is connected to stable cellular data plan or WiFi.'); 
        }
       });

But I am still in favour of the fact that internet reachability check should be provided as a part of the library.

6reactions
yangnana11commented, Jun 27, 2018

Has anyone fixed this problem? I got the same situation with react-native 0.55.4 I can use connectionInfo.type === ‘none’ for android, but ios always return ‘unknown’ even with or without wifi…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netinfo.isConnected always returns true in Android
In iOS it's working fine. But in android always returns true. It doesn't have internet connection (WiFi or Mobile data). It still returns...
Read more >
@react-native-community/netinfo - npm
It should return true if the response indicates that the internet is reachable. Only used on platforms which do not supply internet reachability ......
Read more >
Simplest Way to Get Net Info in React Native - YouTube
In this tutorial we will learn how to check the details of connection using react-native- net-info, we will see the type of the...
Read more >
React Native Managing network connection in 10 minutes
It also identifies the user's current network type (WiFi, cellular, ethernet, and so on). If the connection is cellular, then netinfo will ...
Read more >
Managing network connection status in React Native
If the connection is cellular, then netinfo will also return the ... { type: "wifi", isConnected: true, isInternetReachable: true, ...
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