react-native NetInfo
来源:互联网 发布:steam汽车模拟软件 编辑:程序博客网 时间:2024/05/18 01:22
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, Linking, NetInfo} from 'react-native';export default class D20170503 extends Component { constructor(props){ super(props); this.state = { isCon:false, conInfo:null, isFree:false } } componentDidMount() { //监听网络是否链接 NetInfo.isConnected.addEventListener('isCon',this.isCon.bind(this)); //监听网络变化 NetInfo.addEventListener('changeCon',this.changeCon.bind(this)); //检查网络是否链接 返回true/fase NetInfo.isConnected.fetch().done((b) => { this.setState({ isCon:b }); }); //网络链接的信息 NetInfo.fetch().done((info) => { conInfo:info }); // 用于判断当前活动的连接是否计费 NetInfo.isConnectionExpensive().then((state) =>{ this.setState({ isFree:state }); }); } isCon(b){ this.setState({ isCon:b }); } changeCon(info){ this.setState({ conInfo:info }); } componentWillUnmount() { //移除监听 NetInfo.isConnected.removeEventListener('isCon',this.isCon); NetInfo.removeEventListener('changeCon',this.changeCon); } render() { return ( <View style={styles.container}> <Text>{'是否联网: ' +this.state.isCon}</Text> <Text>{'联网信息: ' +this.state.conInfo}</Text> <Text>{'是否计费: ' +this.state.isFree}</Text> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', },});AppRegistry.registerComponent('D20170503', () => D20170503);
0 0
- react-native NetInfo
- React Native-18.React Native 常用API及实践 NetINfo
- react native学习笔记20——常用API(2)AppState应用前后台、NetInfo网络状态
- react native
- React Native
- React Native
- React- Native
- react-native
- React Native
- React Native
- react native
- React Native
- react-native
- React Native
- react native
- React Native
- React Native
- React Native
- 26进制转10进制,找两个有序集合的交集这两个算法均来自网上,自己整理出来仅供学习,研究之用。有兴趣的可以看看
- 程序员人生之路杂谈
- Java面向对象设计模式(九)——外观模式(Facade)
- Failed to read auto-increment value from storage engine错误的处理方法
- https://wenku.baidu.com/view/2a54b90e52ea551810a6874e.html
- react-native NetInfo
- 二进制位串排列
- python 常见错误
- C++作业5—数组选择、字符串
- 类的生命周期
- Mybatis指定日志输出实现
- spring+mybatis中typehandler怎么配置
- SploitFun Linux x86 Exploit 开发系列教程
- Deep learning on Android