Connect to WiFi with React Native on Android and iOS. This library was written to config iot devices. With iOS 11 Apple introduced NEHotspotConfiguration class for wifi configuration. Library supports same functionality on ios and android.
- Modernizing code and build configuration
- Android is using the newer (WifiNetworkSpecifier API)[https://developer.android.com/reference/android/net/wifi/WifiNetworkSpecifier]
npm install react-native-iot-wifi
Important IoTWifi uses NEHotspotConfigurationManager. To use the NEHotspotConfigurationManager class, you must enable the Hotspot Configuration capability in Xcode.
import Wifi from "react-native-iot-wifi";
// On some platforms location permission is required to setup wifi.
await Wifi.requestPermission();
let allowed = await Wifi.hasPermission();
// You may check if the API is available.
let available = await Wifi.isApiAvailable();
let ssid = await Wifi.getSSID();
try {
// without passphrase
await Wifi.connect("wifi-ssid");
// with passphrase (only WPA is supported)
await Wifi.connect("wifi-ssid", "passphrase");
} catch (error) {
console.log('error: ' + error);
}
try {
await Wifi.disconnect("wifi-ssid");
} catch (error) {
console.log('error: ' + error);
}
See the contributing guide to learn how to contribute to the repository and the development workflow.
See the LICENSE file for license rights and limitations (MIT).