我使用了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中正常工作吗?请帮我。一个星期以来我一直被困住。