react-native: NetInfo returns true when connected to [WiFi|cellular] but Internet is not reachable
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (4 by maintainers)
Commits related to this issue
- fix RCTNetInfo first time connection status (#20820) Summary: Fixes #20804, #8615, https://github.com/facebook/react-native/issues/18368#issuecomment-400610022 Pull Request resolved: https://github.c... — committed to facebook/react-native by karanjthakkar 6 years ago
- fix RCTNetInfo first time connection status (#20820) Summary: Fixes #20804, #8615, https://github.com/facebook/react-native/issues/18368#issuecomment-400610022 Pull Request resolved: https://github.c... — committed to gengjiawen/react-native by karanjthakkar 6 years ago
- fix RCTNetInfo first time connection status (#20820) Summary: Fixes #20804, #8615, https://github.com/facebook/react-native/issues/18368#issuecomment-400610022 Pull Request resolved: https://github.c... — committed to facebook/react-native by karanjthakkar 6 years ago
- fix RCTNetInfo first time connection status (#20820) Summary: Fixes #20804, #8615, https://github.com/facebook/react-native/issues/18368#issuecomment-400610022 Pull Request resolved: https://github.c... — committed to matt-oakes/react-native by karanjthakkar 6 years ago
- fix RCTNetInfo first time connection status (#20820) Summary: Fixes #20804, #8615, https://github.com/facebook/react-native/issues/18368#issuecomment-400610022 Pull Request resolved: https://github.c... — committed to microsoft/react-native-macos by karanjthakkar 6 years ago
@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.
But I am still in favour of the fact that internet reachability check should be provided as a part of the library.
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…
I have the same issue as well. I think it’s necessary to know Internet reachability, especially for WIFI that needs authentication.
Can you edit your post and ensure the repro steps include the specific version you tested this on?