Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect the name of wireless network

Tags:

xcode

ios

iphone

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

like image 874
Charles Vincent Avatar asked Dec 09 '22 19:12

Charles Vincent


2 Answers

This worked perfect 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];
like image 135
Charles Vincent Avatar answered Dec 11 '22 07:12

Charles Vincent


From Developer.apple , you can use CNCopyCurrentNetworkInfo

It Returns the current network info for a given network interface.

CFDictionaryRef CNCopyCurrentNetworkInfo (
   CFStringRef interfaceName
);

It contains a dictionary that containing the interface’s current network info. Ownership follows the Create Rule.

Note:Available in iOS 4.1 and later.

EXAMPLE:

This example will work fine in real device, It may crash in simulator.

Add SystemConfiguration.framework

Import CaptiveNetwork header same as below

#import <SystemConfiguration/CaptiveNetwork.h>

Then write the below code.

    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 both advertises itself on the local network and displays a list of other instances of this application on the network

See the sample Witap application

like image 25
Shamsudheen TK Avatar answered Dec 11 '22 09:12

Shamsudheen TK