From 0e2c7e154b1c532b0d7488e354bd4f7d4f606321 Mon Sep 17 00:00:00 2001 From: Yossi Neiman Date: Tue, 10 Dec 2019 16:05:36 +0200 Subject: [PATCH 1/2] Connect using SSID with prefix if on iOS >= 13 --- src/ios/WifiWizard2.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index 675c571..9a14908 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -51,12 +51,21 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { if (@available(iOS 11.0, *)) { if (ssidString && [ssidString length]) { - NEHotspotConfiguration *configuration = [[NEHotspotConfiguration - alloc] initWithSSID:ssidString - passphrase:passwordString - isWEP:(BOOL)false]; + NEHotspotConfiguration *configuration = [[NEHotspotConfiguration + alloc] initWithSSID:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; - configuration.joinOnce = false; + + if (@available(iOS 13.0, *)) { + NEHotspotConfiguration *configuration = [[NEHotspotConfiguration + alloc] initWithSSIDPrefix:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; + } + + + configuration.joinOnce = false; [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) { From 5d83ccd39e8352e5b586662521f07323a55fb871 Mon Sep 17 00:00:00 2001 From: Yossi Neiman Date: Tue, 24 Dec 2019 08:42:19 +0200 Subject: [PATCH 2/2] fix return statement was always false Thanks @diagus --- src/ios/WifiWizard2.m | 95 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index 9a14908..c2f9511 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -2,7 +2,7 @@ #include #import #import -#import +#import @implementation WifiWizard2 @@ -41,31 +41,32 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { __block CDVPluginResult *pluginResult = nil; - NSString * ssidString; - NSString * passwordString; - NSDictionary* options = [[NSDictionary alloc]init]; - - options = [command argumentAtIndex:0]; - ssidString = [options objectForKey:@"Ssid"]; - passwordString = [options objectForKey:@"Password"]; - - if (@available(iOS 11.0, *)) { - if (ssidString && [ssidString length]) { - NEHotspotConfiguration *configuration = [[NEHotspotConfiguration - alloc] initWithSSID:ssidString - passphrase:passwordString - isWEP:(BOOL)false]; - + NSString * ssidString; + NSString * passwordString; + NSDictionary* options = [[NSDictionary alloc]init]; - if (@available(iOS 13.0, *)) { - NEHotspotConfiguration *configuration = [[NEHotspotConfiguration - alloc] initWithSSIDPrefix:ssidString - passphrase:passwordString - isWEP:(BOOL)false]; - } + options = [command argumentAtIndex:0]; + ssidString = [options objectForKey:@"Ssid"]; + passwordString = [options objectForKey:@"Password"]; + if (@available(iOS 11.0, *)) { + if (ssidString && [ssidString length]) { + NEHotspotConfiguration *configuration; - configuration.joinOnce = false; + configuration = [[NEHotspotConfiguration + alloc] initWithSSID:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; + + + if (@available(iOS 13.0, *)) { + configuration = [[NEHotspotConfiguration + alloc] initWithSSIDPrefix:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; + } + + configuration.joinOnce = false; [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) { @@ -73,8 +74,8 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID" - if ([ssid isEqualToString:ssidString]){ - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString]; + if ([ssid hasPrefix:ssidString]){ + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; }else{ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; } @@ -83,16 +84,16 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { }]; - } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SSID Not provided"]; + } 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"]; + } + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 11+ not available"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - } + } } @@ -147,22 +148,22 @@ - (void)iOSConnectOpenNetwork:(CDVInvokedUrlCommand*)command { - (void)iOSDisconnectNetwork:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = nil; - NSString * ssidString; - NSDictionary* options = [[NSDictionary alloc]init]; - - options = [command argumentAtIndex:0]; - ssidString = [options objectForKey:@"Ssid"]; - - if (@available(iOS 11.0, *)) { - if (ssidString && [ssidString length]) { - [[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssidString]; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString]; - } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SSID Not provided"]; - } - } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 11+ not available"]; - } + NSString * ssidString; + NSDictionary* options = [[NSDictionary alloc]init]; + + options = [command argumentAtIndex:0]; + ssidString = [options objectForKey:@"Ssid"]; + + if (@available(iOS 11.0, *)) { + if (ssidString && [ssidString length]) { + [[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssidString]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SSID Not provided"]; + } + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 11+ not available"]; + } [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];