Skip to content

Commit

Permalink
Merge branch 'fork-master' into feature/use-wifiutils-for-android-wit…
Browse files Browse the repository at this point in the history
…h-semantics

# Conflicts:
#	README.md
#	android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java
  • Loading branch information
Elias Lecomte committed Mar 4, 2020
2 parents f6c5622 + 932eb9b commit 113bc56
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 24 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Close stale issues"
on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.'
stale-issue-label: 'stale'
days-before-stale: 30
days-before-close: 5
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
## [2.3.3](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v2.3.2...v2.3.3) (2020-02-27)


### Bug Fixes

* **iOS:** Fix joinOnce for connectToSSIDPrefix ([#40](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/40)) ([61185a9](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/61185a960b06fe621af3c4c8c8d114036b7ff042))

## [2.3.2](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v2.3.1...v2.3.2) (2020-01-21)


### Bug Fixes

* **android:** Verify connection after enabling network ([#31](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/31)) ([9fa86ee](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/9fa86ee0141535bd142f0e10ff4fd698ccda3533))

## [2.3.1](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v2.3.0...v2.3.1) (2020-01-16)


### Bug Fixes

* **iOS:** Use joinOnce as mentioned https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/2. ([#33](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/33)) ([6c71618](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/6c7161857b17866594ed49cc96b6bda49b74fb40))

# [2.3.0](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v2.2.4...v2.3.0) (2020-01-16)


### Features

* **iOS:** Connect to SSID prefix functions. ([#25](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/25)) ([5b52c97](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/5b52c97461753cb2fb7574964a1415ddaa23ba29))

## [2.2.4](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v2.2.3...v2.2.4) (2019-12-18)


Expand Down
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,49 @@ 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(successCallback: function, errorCallback: function)`
### `loadWifiList(successCallback: function, errorCallback: function)`

Method to get a list of nearby WiFI networks.

#### successCallback( wifiList: string )

Type: `function`

Function to be called if the attempt is successful. It contains a stringified JSONArray of wifiObjects as parameter, each object containing:
Function to be called if the attempt is successful. It contains a stringified JSONArray of wifiObjects as parameter, each object containing:

* `SSID`: The network name.
* `BSSID`: The WiFi BSSID.
Expand All @@ -190,7 +219,7 @@ Type: `function`

Function to be called if any error occurs during the attempt. It contains a `string` as parameter with the error message.

#### Usage
#### Usage

```javascript
WifiManager.loadWifiList(
Expand All @@ -203,7 +232,7 @@ WifiManager.loadWifiList(
error => console.log(error)
);
/**
Result:
Result:
"Wifi 1 - Name of the network"
"Wifi 2 - Name of the network"
"Wifi 3 - Name of the network"
Expand All @@ -215,7 +244,7 @@ Result:

This method is similar to `loadWifiList` but it forcefully starts the wifi scanning on android and in the callback fetches the list.

#### Usage
#### Usage

Same as `loadWifiList`.

Expand Down Expand Up @@ -274,4 +303,4 @@ If you want to use it, you need to add the `android.permission.WRITE_SETTINGS` p

</manifest>

```
```
71 changes: 56 additions & 15 deletions ios/RNWifi.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatu

- (NSString *) getWifiSSID {
NSString *kSSID = (NSString*) kCNNetworkInfoKeySSID;

NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
Expand All @@ -53,21 +53,50 @@ + (BOOL)requiresMainQueueSetup
RCT_EXPORT_METHOD(connectToSSID:(NSString*)ssid
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {

if (@available(iOS 11.0, *)) {
NEHotspotConfiguration* configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid];
[self connectToProtectedSSID:ssid withPassphrase:@"" isWEP:false resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(connectToSSIDPrefix:(NSString*)ssid
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {

if (@available(iOS 13.0, *)) {
NEHotspotConfiguration* configuration = [[NEHotspotConfiguration alloc] initWithSSIDPrefix:ssid];
configuration.joinOnce = false;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
reject(@"nehotspot_error", @"Error while configuring WiFi", error);
} else {
resolve(nil);
}
}];

} else {
reject(@"ios_error", @"Not supported in iOS<13.0", nil);
}
}

RCT_EXPORT_METHOD(connectToProtectedSSIDPrefix:(NSString*)ssid
withPassphrase:(NSString*)passphrase
isWEP:(BOOL)isWEP
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {

if (@available(iOS 13.0, *)) {
NEHotspotConfiguration* configuration = [[NEHotspotConfiguration alloc] initWithSSIDPrefix:ssid passphrase:passphrase isWEP:isWEP];
configuration.joinOnce = true;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
reject(@"nehotspot_error", @"Error while configuring WiFi", error);
} else {
resolve(nil);
}
}];

} else {
reject(@"ios_error", @"Not supported in iOS<11.0", nil);
reject(@"ios_error", @"Not supported in iOS<13.0", nil);
}
}

Expand All @@ -76,19 +105,31 @@ + (BOOL)requiresMainQueueSetup
isWEP:(BOOL)isWEP
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {

// Prevent NEHotspotConfigurationManager error when connecting to an already connected network
if ([ssid isEqualToString:[self getWifiSSID]]) resolve(nil);
if (@available(iOS 11.0, *)) {
NEHotspotConfiguration* configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:passphrase isWEP:isWEP];
configuration.joinOnce = true;
NEHotspotConfiguration* configuration;
// Check if open network
if (passphrase == (id)[NSNull null] || passphrase.length == 0 ) {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid];
} else {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:passphrase isWEP:isWEP];
}
configuration.joinOnce = false;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
reject(@"nehotspot_error", @"Error while configuring WiFi", error);
reject(@"nehotspot_error", [error localizedDescription], error);
} else {
resolve(nil);
// Verify SSID connection
if ([ssid isEqualToString:[self getWifiSSID]]){
resolve(nil);
} else {
reject(@"nehotspot_error", [NSString stringWithFormat:@"%@/%@", @"Unable to connect to ", ssid], nil);
}
}
}];

} else {
reject(@"ios_error", @"Not supported in iOS<11.0", nil);
}
Expand All @@ -97,7 +138,7 @@ + (BOOL)requiresMainQueueSetup
RCT_EXPORT_METHOD(disconnectFromSSID:(NSString*)ssid
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {

if (@available(iOS 11.0, *)) {
[[NEHotspotConfigurationManager sharedManager] getConfiguredSSIDsWithCompletionHandler:^(NSArray<NSString *> *ssids) {
if (ssids != nil && [ssids indexOfObject:ssid] != NSNotFound) {
Expand All @@ -108,7 +149,7 @@ + (BOOL)requiresMainQueueSetup
} else {
reject(@"ios_error", @"Not supported in iOS<11.0", nil);
}

}


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-wifi-reborn",
"version": "2.2.4",
"version": "2.3.3",
"description": "A react-native implementation for viewing and connecting to Wifi networks on Android and iOS devices.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 113bc56

Please sign in to comment.