kaizen
kaizen

Reputation: 1638

How to Simulate Internet Connection on React Native iOS Simulator?

I'm trying to simulate internet connection status on react native ios simulator.

I used NetInfo npm to persistently check for internet connection status.

const unsubscribe = NetInfo.addEventListener(async (state) => {                    
    console.log("Is isInternetReachable?", state.isInternetReachable);                                                            
});    

I tried using "Network Link Conditioner" to simulate internet connection status by switching between 100% loss and Wi-Fi Preset Profiles, but it is not changing the connection status.

enter image description here

Upvotes: 2

Views: 2717

Answers (2)

Deivison Sporteman
Deivison Sporteman

Reputation: 2382

you can try change the configuration of NetInfo to get a better control of how it will check for internet connection

https://github.com/react-native-community/react-native-netinfo#configure

NetInfo.configure({
  reachabilityUrl: 'https://clients3.google.com/generate_204',
  reachabilityTest: async (response) => response.status === 204,
  reachabilityLongTimeout: 60 * 1000, // 60s
  reachabilityShortTimeout: 5 * 1000, // 5s
  reachabilityRequestTimeout: 15 * 1000, // 15s
});

Important: Note that calling this will stop all previously added listeners from being called again. It is best to call this right when your application is started to avoid issues.

Upvotes: 1

Sergei Nikitin
Sergei Nikitin

Reputation: 788

"100% Loss" in not "Internet Unreachable" It means - here is a connection, but it so poor, so 100% packets are lost

Upvotes: 1

Related Questions