New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-wifi-reborn

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-wifi-reborn

A react-native implementation for viewing and connecting to Wifi networks on Android and iOS devices.

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-native-wifi-reborn

ISC license Current npm package version Maintenance Semantic Release Downloads Total downloads Follow @JuanSeBestia

This project is based on the no longer maintained https://github.com/robwalkerco/react-native-wifi.

Getting started

$ npm install react-native-wifi-reborn --save

iOS

You need use enable Access WIFI Information, with correct profile

iOS 13

You need put "Privacy - Location When In Use Usage Description" or "Privacy - Location Always and When In Use Usage Description" in Settings -> info

Android

ACCESS_FINE_LOCATION permission

Since Android 6, you must request the ACCESS_FINE_LOCATION permission at runtime to use the device's Wi-Fi scanning and managing capabilities. In order to accomplish this, you can use the PermissionsAndroid API or React Native Permissions.

Example:

import { PermissionsAndroid } from 'react-native';

const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      {
        title: 'Location permission is required for WiFi connections',
        message:
          'This app needs location permission as this is required  ' +
          'to scan for wifi networks.',
        buttonNegative: 'DENY',
        buttonPositive: 'ALLOW',
      },
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    // You can now use react-native-wifi-reborn
} else {
    // Permission denied
}

Autolinking (React Native 60+)

This library is correctly autolinked on React Native 60+ 🎉.

When using Wix React Native Navigation
Android

While the library is included (via settings.gradle) and added (via build.gradle), you still need to manually added to your MainApplication.

import com.reactlibrary.RNWifiPackage;

public class MainApplication extends NavigationApplication {
@Override
	public List<ReactPackage> createAdditionalReactPackages() {
	return Arrays.asList(
		...,
		new RNWifiPackage());
	}
}

$ react-native link react-native-wifi-reborn

Manual linking

iOS
  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-wifi-reborn and add RNWifi.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNWifi.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<
Android
  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNWifiPackage; to the imports at the top of the file
  • Add new RNWifiPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-wifi-reborn'
    project(':react-native-wifi-reborn').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-wifi-reborn/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      implementation project(':react-native-wifi-reborn')
    

Usage

import WifiManager from "react-native-wifi-reborn";

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!");
  }
);

Methods

The api documentation is in progress.

Android & iOS

The following methods work on both Android and iOS

connectToProtectedSSID(SSID: string, password: string, isWEP: boolean): Promise

Returns a promise that resolves when connected or rejects with the error when it couldn't connect to the wifi network.

SSID

Type: string

The SSID of the wifi network to connect with.

password

Type: string

The password of the wifi network to connect with.

isWep

Type: boolean Used on iOS. If true, the network is WEP Wi-Fi; otherwise it is a WPA or WPA2 personal Wi-Fi network.

Errors:
  • location permission missing: The location permission (ACCESS_FINE_LOCATION) is not granted (android 6+).
  • location off: The location service needs to be turned on (android 6+).
  • failed: Could not connect to the network. Could be due to multiple reasons; not in rang or wrong password.

getCurrentWifiSSID(): Promise

Only iOS

The following methods work only on iOS

connectToSSID(ssid: string): Promise

connectToSSIDPrefix(ssid: string): Promise

disconnectFromSSID(ssid: string): Promise

connectToProtectedSSIDPrefix(SSIDPrefix: string, password: string, isWep: boolean): Promise

Use this function when you want to match a known SSID prefix, but don’t have a full SSID. If the system finds multiple Wi-Fi networks whose SSID string matches the given prefix, it selects the network with the greatest signal strength.

SSIDPrefix

Type: string A prefix string to match the SSID of a Wi-Fi network.

password

Type: string The password of the wifi network to connect with.

isWep

Type: boolean Used on iOS. If YES, the network is WEP Wi-Fi; otherwise it is a WPA or WPA2 personal Wi-Fi network.

Errors:
  • notInRange: The WIFI network is not currently in range.

  • addOrUpdateFailed: Could not add or update the network configuration.

  • disconnectFailed: Disconnecting from the network failed. This is done as part of the connect flow.

  • connectNetworkFailed: Could not connect to network.

Only Android

The following methods work only on Android

loadWifiList(): Promise<Array<WifiEntry>>

Returns a list of nearby WiFI networks.

  • SSID: The network name.
  • BSSID: The WiFi BSSID.
  • capabilities: Describes the authentication, key management, and encryption schemes supported by the access point.
  • frequency: The primary 20 MHz frequency (in MHz) of the channel over which the client is communicating with the access point.
  • level: The detected signal level in dBm, also known as the RSSI.
  • timestamp: timestamp in microseconds (since boot) when this result was last seen.

reScanAndLoadWifiList(): Promise<Array<string>>

Similar to loadWifiList but it forcefully starts a new WiFi scan and only passes the results when the scan is done.

isEnabled(): Promise<boolean>

Method to check if WiFi is enabled.

const enabled = await WifiManager.isEnabled();
this.setState({wifiIsEnabled: enabled});

setEnabled(enabled: boolean)

Method to set the WiFi on or off on the user's device.

WifiManager.setEnabled(true); //set WiFi ON
WifiManager.setEnabled(false); //set WiFi OFF

connectionStatus(): Promise<boolean>

Returns if the device is currently connected to a WiFi network.

disconnect()

Disconnect currently connected WiFi network.

getBSSID(): Promise<string>

Returns the BSSID (basic service set identifier) of the currently connected WiFi network.

getCurrentSignalStrength(): Promise<number>

Returns the RSSI (received signal strength indicator) of the currently connected WiFi network.

getFrequency(): Promise<number>

Returns the frequency of the currently connected WiFi network.

getIP(): Promise<number>

Returns the IP of the currently connected WiFi network.

isRemoveWifiNetwork(ssid: String): Promise<boolean>

This method will remove the wifi network configuration. If you are connected to that network, it will disconnect.

forceWifiUsage(useWifi: boolean): Promise

Use this to execute api calls to a wifi network that does not have internet access. Useful for commissioning IoT devices. This will route all app network requests to the network (instead of the mobile connection). It is important to disable it again after using as even when the app disconnects from the wifi network it will keep on routing everything to wifi.

Conventions

Keywords

FAQs

Package last updated on 01 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc