How to check network status in a response application

I fight for this point that if in my mobile Iā€™m poorly connected to the network, some, as I call the service, it will take more time to call the service

  • Is it possible to increase the sampling timeout (or)
  • How to tell the user that you have a bad internet connection.

    To check the Internet connection, I used networkInfo, but it only helps to connect, whether there is one or not, but it does not provide any information about the network speed.

If possible, someone can give me advice on how, how can I solve this, Any help that is really appreciated I use the reactive version: 0.29.0

+10
source share
3 answers

If you just want to find out if the device has an active Internet connection, you can use, for example, isConnected from React Native NetInfo :

import {NetInfo} from 'react-native'; NetInfo.isConnected.addEventListener('connectionChange', (hasInternetConnection) = console.debug('hasInternetConnection:', hasInternetConnection)); 

However, I'm not sure how to figure out how good the connection is.

+10
source
 NetInfo.getConnectionInfo().then((connectionInfo) => { console.log('Initial, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType); }); function handleFirstConnectivityChange(connectionInfo) { console.log('First change, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType); NetInfo.removeEventListener( 'connectionChange', handleFirstConnectivityChange ); } NetInfo.addEventListener( 'connectionChange', handleFirstConnectivityChange ); 

this is a copy of the code in the relevant documentation , the effective type indicates whether the network is 2G, 3G, EDGE or 4G.

+4
source

Here is an example:

 import { NetInfo,Alert } from 'react-native'; const netStatus = await NetInfo.fetch() if (netStatus === 'none' || netStatus === 'NONE') { Alert.alert("Internet not connected.!!!") return [] }else{ Alert.alert("Internet connected.!!! ") } 
0
source

Source: https://habr.com/ru/post/1014139/


All Articles