Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
- iOSConnectNetwork now will return a promise and only return true if…
Browse files Browse the repository at this point in the history
… we have connected to the specified network.

- JoinOnce is now set to false to avoid early disconnecting from the network
  • Loading branch information
Nicholas Clancy committed Jun 17, 2018
1 parent 54b5abd commit ab867cd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##### Latest Stable Release: v2.4.0 (20/03/2018)
Run `cordova plugin add [email protected]`

##### Latest Dev Release: v2.4.9 (18/06/2018)
##### Latest Dev Release: v2.4.10 (18/06/2018)
*Note:* The latest Dev Release may be unstable. It is highly recommend installing from the latest stable release via above.


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordovanetworkmanager",
"version": "2.4.9",
"version": "2.4.10",
"cordova": {
"id": "cordovanetworkmanager",
"platforms": [
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordovanetworkmanager"
version="2.4.9">
version="2.4.10">

<name>cordovaNetworkManager</name>
<description>Cordova Network Manager for Android and iOS</description>
Expand Down
31 changes: 24 additions & 7 deletions src/ios/cordovaNetworkManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ - (id)fetchSSIDInfo {
}

- (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command {
CDVPluginResult *pluginResult = nil;

__block CDVPluginResult *pluginResult = nil;

NSString * ssidString;
NSString * passwordString;
Expand All @@ -35,18 +36,34 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command {
passphrase:passwordString
isWEP:(BOOL)false];

configuration.joinOnce = YES;
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString];
configuration.joinOnce = false;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {

NSDictionary *r = [self fetchSSIDInfo];

NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID"

if ([ssid isEqualToString:ssidString]){
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString];
}else{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description];
}
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}];


} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SSID Not provided"];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 11+ not available"];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}

[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}

- (void)iOSDisconnectNetwork:(CDVInvokedUrlCommand*)command {
Expand Down

0 comments on commit ab867cd

Please sign in to comment.