您是否知道如何通过React Native iOS应用检查WIFI是否已打开。由于iOS设备上的aGPS,必须打开WIFI才能使我们的位置敏感应用有效运行,并且在关闭时我们希望通知用户。
有什么想法如何在iOS的React Native应用中实现这一目标吗?
答案 0 :(得分:1)
使用NetInfo
检查设备是否已在React Native中连接到wifi /蜂窝。
NetInfo公开有关在线/离线状态的信息
NetInfo.getConnectionInfo().then((connectionInfo) => {
console.log('Initial, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
});
function handleFirstConnectivityChange(connectionInfo) {
console.log('First change, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
NetInfo.removeEventListener(
'connectionChange',
handleFirstConnectivityChange
);
}
NetInfo.addEventListener(
'connectionChange',
handleFirstConnectivityChange
);
ConnectionType
描述了设备用于与网络通信的连接类型。
ConnectionType
的跨平台值:
none - device is offline
wifi - device is online and connected via wifi, or is the iOS simulator
cellular - device is connected via Edge, 3G, WiMax, or LTE
unknown - error case and the network status is unknown
有关更多信息,请访问https://facebook.github.io/react-native/docs/netinfo
答案 1 :(得分:1)
我不确定您将如何处理WIFI信息,但是如果您需要简单的信息,我会使用react-native netinfo:https://github.com/react-native-community/react-native-netinfo#react-native-communitynetinfo 如果您使用世博会,我推荐这个,网络https://docs.expo.io/versions/latest/sdk/network/