Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect using SSID with prefix if on iOS >= 13 #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions src/ios/WifiWizard2.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <ifaddrs.h>
#import <net/if.h>
#import <SystemConfiguration/CaptiveNetwork.h>
#import <NetworkExtension/NetworkExtension.h>
#import <NetworkExtension/NetworkExtension.h>

@implementation WifiWizard2

Expand Down Expand Up @@ -41,31 +41,41 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command {

__block CDVPluginResult *pluginResult = nil;

NSString * ssidString;
NSString * passwordString;
NSDictionary* options = [[NSDictionary alloc]init];
NSString * ssidString;
NSString * passwordString;
NSDictionary* options = [[NSDictionary alloc]init];

options = [command argumentAtIndex:0];
ssidString = [options objectForKey:@"Ssid"];
passwordString = [options objectForKey:@"Password"];
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];
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) {

NSDictionary *r = [self fetchSSIDInfo];

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];
}
Expand All @@ -74,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];
}
}


}
Expand Down Expand Up @@ -138,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];
Expand Down