From ab867cd8c1e0a6f1f40abef1a487ba2428ba665f Mon Sep 17 00:00:00 2001 From: Nicholas Clancy Date: Mon, 18 Jun 2018 08:26:33 +1000 Subject: [PATCH] - iOSConnectNetwork now will return a promise and only return true if we have connected to the specified network. - JoinOnce is now set to false to avoid early disconnecting from the network --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- src/ios/cordovaNetworkManager.m | 31 ++++++++++++++++++++++++------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 948c422..a103a83 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ##### Latest Stable Release: v2.4.0 (20/03/2018) Run `cordova plugin add cordovanetworkmanager@2.4.0` -##### 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. diff --git a/package.json b/package.json index 22439dc..562b2a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordovanetworkmanager", - "version": "2.4.9", + "version": "2.4.10", "cordova": { "id": "cordovanetworkmanager", "platforms": [ diff --git a/plugin.xml b/plugin.xml index 4350faa..b147d82 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="2.4.10"> cordovaNetworkManager Cordova Network Manager for Android and iOS diff --git a/src/ios/cordovaNetworkManager.m b/src/ios/cordovaNetworkManager.m index 119cba0..e003b20 100644 --- a/src/ios/cordovaNetworkManager.m +++ b/src/ios/cordovaNetworkManager.m @@ -18,7 +18,8 @@ - (id)fetchSSIDInfo { } - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { - CDVPluginResult *pluginResult = nil; + + __block CDVPluginResult *pluginResult = nil; NSString * ssidString; NSString * passwordString; @@ -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 {