componentWillMount(){
NetInfo.getConnectionInfo().then((connectionInfo) => {
console.log('Initial, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
if(connectionInfo.type=='none'){
//没有网络
}else{
//有网络
}
});
NetInfo.addEventListener(
'connectionChange',
this.handleFirstConnectivityChange.bind(this)
);
}
componentWillUnmount(){
NetInfo.removeEventListener(
'connectionChange',
this.handleFirstConnectivityChange.bind(this)
);
}
handleFirstConnectivityChange(connectionInfo){
let that=this;
console.log('网络事件监听, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
if(connectionInfo.type=='none'){
//没有网络
}else{
//有网络
}
}