1

Platforms

This issue is related to iOS.

Versions

  • iOS: 12.4.1
  • react-native-netinfo: "^5.5.0"
  • react-native: "0.61.5"
  • react: "16.9.0"

Description

I'm working on implementing network status check in a project with dynamic data and checking for internet reachability whenever an API call is made or the app state changes.

My issue is that the key isInternetReachable is always returning false for a minute before returning the correct status whenever app comes to foreground from background even though internet is reachable. The issue is happening on iOS real device and everything is working fine on iOS simulator and android real device.

Reproducible Demo

let state;
componentDidMount() {
        // Adding AppState event listener
        AppState.addEventListener('change', this._handleAppStateChange);
        // Adding NetInfo event listener
        this._subscription = NetInfo.addEventListener(
            this._handleConnectionInfoChange,
        );
    }
 componentWillUnmount() {
        // Removing AppState event listener
        AppState.removeEventListener('change', this._handleAppStateChange);
        // Removing NetInfo event listener
        this._subscription && this._subscription();
    }
_handleAppStateChange = async nextAppState => {
        if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
            state = await NetInfo.fetch();
            });
        }
        if (this.state.appState.match(/active|inactive/) && nextAppState === 'background') {
            state = await NetInfo.fetch();
            });
        }
        if (this.state.appState.match(/active|background/) && nextAppState === 'inactive') {
            state = await NetInfo.fetch();
            });
        }
        this.setState({ appState: nextAppState });
    };
 getJobs = async (index) => {
        // fetching status of internet connection
        state = await NetInfo.fetch();
            if (state.isInternetReachable === false) {
                Alert.alert(Constants.k_APP_NAME, Constants.k_OFFLINE_TEXT);
            } else {
                this.props.callService(item, false);
            }
        }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Sahitya D
  • 154
  • 3
  • 10
  • A note on the use of **bold** formatting: for reasons of readability, this should be used sparingly. The purpose of it is to draw attention to something, so use it one or twice - if at all - in a whole post. Bolding key phrases is pointless, and much less readable than not bolding at all. – halfer Mar 20 '20 at 11:12
  • open an issue on github rather than stackoverflow. – TheEhsanSarshar Sep 11 '20 at 07:13
  • The same problem, bug report created in the issue section https://github.com/react-native-netinfo/react-native-netinfo/issues/538 – Material Dec 18 '21 at 17:12

0 Answers0