Simranjit Singh
Simranjit Singh

Reputation: 51

getting crash while using NetInfo.isConnected in ios react native

I am trying to read the networkstatechange in react-native ios code as :

componentDidMound(){
NetInfo.isConnected.addEventListener('connectionChange',this._handleNetworkStateChange);
}

componentWillUnmount(){
NetInfo.isConnected.removeEventListener('connectionChange',this._handleNetworkStateChange);
}

_handleNetworkStateChange = (isConnected) => {
this.setState({
netStatus : isConnected
})
}

1)When nework is Active : while network state is changing from online to offline. App(ios) is directely crashing instead of reading state.

2)when network is inActive/offline initially : while changing network state from offline to online, it works properly. shows and loads the view perfectly.

any help would be appreciated as i have gone through many tutorials but not getting the solution.Thanks in advance.

Upvotes: 3

Views: 438

Answers (0)

Related Questions