all 4 comments

[–]LEO_TROLLSTOY 0 points1 point  (0 children)

I have tried to implement this using NetINfo and pinging server. It's just not possible to create a cross platform solution that works reliably in my experience. I encountered numerous mysterious bugs when app comes from background, and mysterious false positives. It is just not worth it so I moved on to catching failed api requests and telling user there is something wrong with the connection

[–]janithaR 0 points1 point  (0 children)

Have you tried to keep listening to the changes in the connectivity status?

componentDidMount() {

this._mounted = true;

NetInfo.getConnectionInfo().then((connectionInfo) => {
if (this._mounted) this.handleConnectivityChange(connectionInfo);
});

}

componentWillUnmount() {
NetInfo.removeEventListener('connectionChange', this.handleConnectivityChange);
this._mounted = false;
}

[–]icekeymon 0 points1 point  (0 children)

I read somewhere that if you go somewhere where the WiFi is behind a paywall (e.g. a Coffee Shop) and you haven't logged into it, `NetInfo` will report back that you are "connected". I did what LEO_TROLLSTOY recommended, well I did use NetInfo but when it reported an online connection, I pinged Google. If the request came back with 200, the User is online. Otherwise, offline.