From cf3c7010590bb026ff2e3e9f8c9998849b58f49a Mon Sep 17 00:00:00 2001 From: Kossmo Date: Wed, 18 May 2022 16:17:41 +0200 Subject: [PATCH] getConnectedSSID ios 13+ Change the way you fect ssid for ios 13+ --- src/ios/WifiWizard2.m | 44 +++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index 675c571..d9d1f45 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -3,6 +3,7 @@ #import #import #import +#import @implementation WifiWizard2 @@ -160,21 +161,44 @@ - (void)iOSDisconnectNetwork:(CDVInvokedUrlCommand*)command { } - (void)getConnectedSSID:(CDVInvokedUrlCommand*)command { - CDVPluginResult *pluginResult = nil; - NSDictionary *r = [self fetchSSIDInfo]; - - NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID" - - if (ssid && [ssid length]) { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; + __block NSString *ssid = nil; + __block CDVPluginResult *pluginResult = nil; + if (@available(iOS 14.0, *)) { + [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) { + ssid = [currentNetwork SSID]; + NSLog(@"debugjeje"); + + NSLog(@"%@", currentNetwork); + if (ssid && [ssid length]) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not available"]; + } + [self.commandDelegate sendPluginResult:pluginResult + callbackId:command.callbackId]; + }]; } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not available"]; + NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces(); + NSDictionary *info; + for (NSString *ifnam in ifs) { + info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam); + if (info && [info count]) { + ssid = [info objectForKey:@"SSID"]; + break; + } + } + if (ssid && [ssid length]) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not available"]; + } + [self.commandDelegate sendPluginResult:pluginResult + callbackId:command.callbackId]; } - [self.commandDelegate sendPluginResult:pluginResult - callbackId:command.callbackId]; } + - (void)getConnectedBSSID:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = nil; NSDictionary *r = [self fetchSSIDInfo];