Wireless Name Discovery

Is it possible to run a method that will return the name of the wireless network to which the user is connected? Inside my application, I want to be able to return the name of the wireless network to which the user is connected.

+4
source share
2 answers

This worked fine for me:

#import <SystemConfiguration/CaptiveNetwork.h> CFArrayRef myArray = CNCopySupportedInterfaces(); CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); // NSLog(@"SSID: %@",CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID)); NSString *networkName = CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID); if ([networkName isEqualToString:@"Hot Dog"]) { self.storeNameController = [[StoreDataController alloc] init]; [self.storeNameController addStoreNamesObject]; } else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Connection Failed" message: @"Please connect to the Hot Dog network and try again" delegate: self cancelButtonTitle: @"Close" otherButtonTitles: nil]; [alert show]; 
+8
source

From Developer.apple you can use CNCopyCurrentNetworkInfo

It returns current network information for a given network interface.

 CFDictionaryRef CNCopyCurrentNetworkInfo ( CFStringRef interfaceName ); 

It contains a dictionary containing information about the current network information of the interfaces. Ownership follows the creation of the rule.

Note : Available in iOS 4.1 and later .

Example:

This example works fine in a real device, it may crash in the simulator.

Add SystemConfiguration.framework

Import CaptiveNetwork as below

#import <SystemConfiguration/CaptiveNetwork.h>

Then write the code below.

  CFArrayRef myArray = CNCopySupportedInterfaces(); // Get the dictionary containing the captive network infomation CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); NSLog(@"Information of the network we're connected to: %@", captiveNtwrkDict); NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict; NSString* ssid = [dict objectForKey:@"SSID"]; NSLog(@"network name: %@",ssid); 

or

Using Bonjour , the application declares itself on the local network and displays a list of other instances of this application on the network

See sample Witap application

+6
source

Source: https://habr.com/ru/post/1443652/


All Articles