Connection on background / locked screen (no internet connection with a stable internet connection.)
After returning from the background isConnected mostly returns false firstly and after a while returns true.
Its happening in IOS and Android real device connected to Wifi
Code:
useEffect(() => {
const removeNetInfoSubscription = NetInfo.addEventListener(state => {
const isConnected = state.isConnected ?? true;
const isInternetReachable = state.isInternetReachable ?? true;
const offline = !isConnected || !isInternetReachable;
setNetworkConnectionOffline(offline);
});
return () => removeNetInfoSubscription();
}, []);
the same on both iOS and android
@react-native-community/netinfo: 9.3.4 react-native: 0.71.0
Any updates on this one?
@ValeriyaZavozova in an open source repository, "updates" are visible to all (so you'd see them if they existed), but do not typically create progress unless they contain the magic phrase "I've investigated this and posted a PR here <link to PR>"
Still an issue. Been digging into this but no luck.
My problem seemed to be that I was doing ->
useEffect(() => {
const unsubscribe = NetInfo.addEventListener((state) => {
});
return unsubscribe
}, []);
But this worked ->
useEffect(() => {
const unsubscribe = NetInfo.addEventListener((state) => {
});
return () => {
unsubscribe();
};
}, []);
Its still a bit slow to change the state sometime and debugging the simulator or a build to a device was difficult because when the internet is turned off the connection to the debugger went off.