我正在构建一个本机应用程序并实现NetInfo。它适用于ios,但不适用于android

时间:2019-09-25 06:19:10

标签: android react-native react-native-community-netinfo

我使用了react-native-community / netinfo版本-“ ^ 4.2.2”。它可以在ios上运行,但不能在android上运行。

我尝试从react-native以及依赖项导入,但是它们都不起作用。我也在AndroidManifest.xml中添加了权限。

 componentDidMount() {
    console.log("inside componentdidmount()")
    NetInfo.isConnected.addEventListener(
      "connectionChange",
      this.handleConnectivityChange
    );
  }

  componentWillUnmount() {
    console.log("inside componentWillUnmount")
    NetInfo.isConnected.removeEventListener(
      "connectionChange",
      this.handleConnectivityChange
    );
  }

  handleConnectivityChange = isConnected => {
    console.log("inside handleConnectivityChange")
    this.props.checkOnlineStatus(isConnected);
    console.log("check ", isConnected)
    this.setState({ isConnected });
  };

我还应该添加其他内容以使其在android中正常工作吗?请帮我。一个星期以来我一直被困住。

0 个答案:

没有答案