$ npm install react-native-wifi --save
$ react-native link react-native-wifi
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-wifi
and add RNWifi.xcodeproj
libRNWifi.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainActivity.java
import com.reactlibrary.RNWifiPackage;
to the imports at the top of the filenew RNWifiPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-wifi'
project(':react-native-wifi').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi/android')
android/app/build.gradle
:
compile project(':react-native-wifi')
import WifiManager from 'react-native-wifi';
WifiManager.connectToProtectedSSID(ssid, password, isWep)
.then(() => {
console.log('Connected successfully!')
}, () => {
console.log('Connection failed!')
})
WifiManager.getCurrentWifiSSID()
.then((ssid) => {
console.log("Your current connected wifi SSID is " + ssid)
}, () => {
console.log('Cannot get current SSID!')
})