在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ 網(wǎng)絡(luò)信息
JavaScript 環(huán)境
計時器
Native 模塊(iOS)
入門
在設(shè)備上運行
ProgressBarAndroid
iOS 應(yīng)用程序狀態(tài)
網(wǎng)絡(luò)
ToolbarAndroid
測試
輔助功能
網(wǎng)絡(luò)信息
DrawerLayoutAndroid
樣式表
手勢應(yīng)答系統(tǒng)
與現(xiàn)有的應(yīng)用程序集成
樣式
教程
不透明觸摸
調(diào)試 React Native 應(yīng)用
iOS 活動指示器
導(dǎo)航器
無反饋觸摸
動畫布局
Web 視圖
鏈接庫
像素比率
React Native 官網(wǎng)首頁介紹
iOS 導(dǎo)航器
交互管理器
全景響應(yīng)器
SwitchAndroid
TabBarIOS.Item
相機滾動
ToastAndroid
iOS 震動
BackAndroid
文本輸入
iOS 選擇器
應(yīng)用程序注冊表
iOS 開關(guān)
滾動視圖
iOS 日期選擇器
iOS 警告
iOS 鏈接
視圖
圖片
列表視圖
異步存儲
Native UI 組件(Android)
iOS 滑塊
Map 視圖
高亮觸摸
iOS 推送通知
文本
定位
iOS 狀態(tài)欄
Native UI 組件(iOS)
在設(shè)備上運行(Android)
Native 模塊(Android)
Flexbox
已知 Issues
iOS 選項卡
安裝 Android 運行環(huán)境

網(wǎng)絡(luò)信息

網(wǎng)絡(luò)信息公開在線或者離線信息

reachabilityIOS

異步確定設(shè)備是否處于在線狀態(tài)并且在蜂窩網(wǎng)絡(luò)。

  • None - 設(shè)備處于離線狀態(tài)
  • WiFi - 設(shè)備處于在線狀態(tài),并且通過 WiFi 或者是 iOS 模擬器連接
  • Cell - 設(shè)備通過網(wǎng)絡(luò)連接,3G,WiMax,或者 LTE 進(jìn)行連接
  • Unknown - 錯誤情況,并且網(wǎng)絡(luò)狀態(tài)未知
    NetInfo.reachabilityIOS.fetch().done((reach) => {
      console.log('Initial: ' + reach);
    });
    function handleFirstReachabilityChange(reach) {
      console.log('First change: ' + reach);
      NetInfo.reachabilityIOS.removeEventListener(
        'change',
        handleFirstReachabilityChange
      );
    }
    NetInfo.reachabilityIOS.addEventListener(
      'change',
      handleFirstReachabilityChange
    );

連接狀態(tài)

在所有的平臺上都可用。異步獲取一個布爾值來確定網(wǎng)絡(luò)連接。

    NetInfo.isConnected.fetch().done((isConnected) => {
      console.log('First, is ' + (isConnected ? 'online' : 'offline'));
    });
    function handleFirstConnectivityChange(isConnected) {
      console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
      NetInfo.isConnected.removeEventListener(
        'change',
        handleFirstConnectivityChange
      );
    }
    NetInfo.isConnected.addEventListener(
      'change',
      handleFirstConnectivityChange
    );

例子

Edit on GitHub

    'use strict';
    var React = require('react-native');
    var {
      NetInfo,
      Text,
      View
    } = React;
    var ReachabilitySubscription = React.createClass({
      getInitialState() {
        return {
          reachabilityHistory: [],
        };
      },
      componentDidMount: function() {
        NetInfo.reachabilityIOS.addEventListener(
          'change',
          this._handleReachabilityChange
        );
      },
      componentWillUnmount: function() {
        NetInfo.reachabilityIOS.removeEventListener(
          'change',
          this._handleReachabilityChange
        );
      },
      _handleReachabilityChange: function(reachability) {
        var reachabilityHistory = this.state.reachabilityHistory.slice();
        reachabilityHistory.push(reachability);
        this.setState({
          reachabilityHistory,
        });
      },
      render() {
        return (
          <View>
            <Text>{JSON.stringify(this.state.reachabilityHistory)}</Text>
          </View>
        );
      }
    });
    var ReachabilityCurrent = React.createClass({
      getInitialState() {
        return {
          reachability: null,
        };
      },
      componentDidMount: function() {
        NetInfo.reachabilityIOS.addEventListener(
          'change',
          this._handleReachabilityChange
        );
        NetInfo.reachabilityIOS.fetch().done(
          (reachability) => { this.setState({reachability}); }
        );
      },
      componentWillUnmount: function() {
        NetInfo.reachabilityIOS.removeEventListener(
          'change',
          this._handleReachabilityChange
        );
      },
      _handleReachabilityChange: function(reachability) {
        this.setState({
          reachability,
       });
      },
      render() {
        return (
          <View>
            <Text>{this.state.reachability}</Text>
          </View>
        );
      }
    });
    var IsConnected = React.createClass({
      getInitialState() {
        return {
          isConnected: null,
        };
      },
      componentDidMount: function() {
        NetInfo.isConnected.addEventListener(
          'change',
          this._handleConnectivityChange
        );
        NetInfo.isConnected.fetch().done(
          (isConnected) => { this.setState({isConnected}); }
        );
      },
      componentWillUnmount: function() {
        NetInfo.isConnected.removeEventListener(
          'change',
          this._handleConnectivityChange
        );
      },
      _handleConnectivityChange: function(isConnected) {
        this.setState({
          isConnected,
        });
      },
      render() {
        return (
          <View>
            <Text>{this.state.isConnected ? 'Online' : 'Offline'}</Text>
          </View>
        );
      }
    });
    exports.title = 'NetInfo';
    exports.description = 'Monitor network status';
    exports.examples = [
      {
        title: 'NetInfo.isConnected',
        description: 'Asyncronously load and observe connectivity',
        render(): ReactElement { return <IsConnected />; }
      },
      {
        title: 'NetInfo.reachabilityIOS',
        description: 'Asyncronously load and observe iOS reachability',
        render(): ReactElement { return <ReachabilityCurrent />; }
      },
      {
        title: 'NetInfo.reachabilityIOS',
        description: 'Observed updates to iOS reachability',
        render(): ReactElement { return <ReachabilitySubscription />; }
      },
    ];
上一篇:圖片下一篇:iOS 震動