WiFi reconnection not recognized when App is inactive
See original GitHub issueEnvironment
System: OS: macOS Mojave 10.14.6 CPU: (4) x64 Intel® Core™ i5-5257U CPU @ 2.70GHz Memory: 550.87 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 11.14.0 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 11.2/11B52 - /usr/bin/xcodebuild npmPackages: @react-native-community/cli: 2.9.0 => 2.9.0 react: 16.9.0 => 16.9.0 react-native: 0.61.2 => 0.61.2 npmGlobalPackages: react-native-cli: 2.0.1
Platforms
The issue only happens on iOS, everything works as expected on Android.
Versions
- Android: N/A
- iOS: 13.1.2
- react-native-netinfo: 4.6.0
- react-native: 0.61.2
- react: 16.9.0
Description
Im using the following code to display a message when the user is offline:
<NetworkProvider>
<NetworkConsumer>
{({ isConnected }) =>
isConnected ? null : (
<View style={pageStyles.container}>
<Text style={pageStyles.text}>{t('app.offline')}</Text>
</View>
)
}
</NetworkConsumer>
</NetworkProvider>
When I turn of WiFi the mesage shows as expected. Also the message disappears as expected if I turn WiFi back on provided the App is open while the connection is created. However should the control center be open while the WiFi connection changes from disconnected to connected, (e.g. open control center, enable WiFi, wait for connection, close control center) then the message stating the user is offline will not disappear. The same thing happens, if I disable WiFi while in the App, then let the App go to the background, enable WiFi again and wait for it to connect. Getting the App back out from the background later, it still shows the offline message and the message also doesn’t go away with time.
I also found the following odd behaviour: When I am online and have an offline message that does not disappear on screen 1 and I navigate to another screen (screen 2) that would also render an offline message if I would be offline, this screen does not show an offline message (as it should be). Navigating back to screen 1 I will see the offline message again (not as it should be) even though screen 2 obviously realized that the user is online.
Also I’m testing on a real iOS device not on a Simulator.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9
@matt-oakes I think I have a similar problem. Sometimes, when the app is in the foreground and I lock the screen of an iPhone for 10-30 seconds (try with different time ranges) and unlock it later, the app states that it has no internet connection.
I’ve created a minimal reproducible demo, you can grab it from here
Once the bug appears - even if you add a button to perform a forced connection check - this will give no result, as the library will continue to return
{ isInternetReachable: false }
for some time, even though it’s not true. The issue goes away automatically after a minute or so, or after restarting the WiFi through ios control center (the app should be in the foreground).Android version seems to work fine.
Facing the same issue on iOS. Tried re-fetching the network status whenever app state changes using AppState and still issue is not gone. Did u succeed in finding any solution?