Skip to content
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
63 changes: 45 additions & 18 deletions src/ios/NXWWifiWizard.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#import "NXWWifiWizard.h"
#include <ifaddrs.h>
#import <net/if.h>
#import <SystemConfiguration/CaptiveNetwork.h>


@implementation NXWWifiWizard

- (id)fetchSSIDInfo {
Expand All @@ -16,56 +19,74 @@ - (id)fetchSSIDInfo {
return info;
}

- (BOOL) isWiFiEnabled {
// see http://www.enigmaticape.com/blog/determine-wifi-enabled-ios-one-weird-trick
NSCountedSet * cset = [NSCountedSet new];

struct ifaddrs *interfaces = NULL;
// retrieve the current interfaces - returns 0 on success
int success = getifaddrs(&interfaces);
if(success == 0){
for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {
if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) {
[cset addObject:[NSString stringWithUTF8String:interface->ifa_name]];
}
}
}

return [cset countForObject:@"awdl0"] > 1 ? YES : NO;
}

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

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

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

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

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

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

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

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

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

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

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
Expand All @@ -81,9 +102,9 @@ - (void)startScan:(CDVInvokedUrlCommand*)command {

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

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];

[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
Expand All @@ -107,20 +128,26 @@ - (void)getConnectedSSID:(CDVInvokedUrlCommand*)command {
- (void)getConnectedBSSID:(CDVInvokedUrlCommand*)command {
CDVPluginResult *pluginResult = nil;
NSDictionary *r = [self fetchSSIDInfo];

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

if (bssid && [bssid length]) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:bssid];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not available"];
}

[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
- (void)isWifiEnabled:(CDVInvokedUrlCommand*)command {

CDVPluginResult *pluginResult = nil;
NSString *isWifiOn = [self isWiFiEnabled] ? @"1" : @"0";

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:isWifiOn];

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

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