IOS get WiFi SSID name
SSID full service Set IDentifier, that is, the public name of the WiFi network. iOS 4.1 or later provides a public way to get that information.
First add a frame: systemconfiguration.framework
1 #import<SystemConfiguration/CaptiveNetwork.h>2- (ID) Fetchssidinfo3 {4Nsarray *ifs = (ID) cncopysupportedinterfaces (); 5NSLog (@"%s:supported interfaces:%@", __func__, IFS); 6 IDinfo =Nil;7 for(NSString *ifnaminchIFS)8 { 9info = (ID) Cncopycurrentnetworkinfo ((cfstringref) Ifnam); TenNSLog (@"%s:%@ =%@", __func__, Ifnam, info); One if(Info &&[Info count]) A { - Break; - } the [info release]; - } - [IFS release]; - return[Info autorelease]; + } - + A-(NSString *) Currentwifissid { at //Does not work on the simulator. -NSString *ssid =Nil; -Nsarray *ifs = (ID) cncopysupportedinterfaces (); -NSLog (@"ifs:%@", IFS); - for(NSString *ifnaminchIFS) { -Nsdictionary *info = (ID) Cncopycurrentnetworkinfo ((cfstringref) ifnam); inNSLog (@"dici:%@", [info AllKeys]); - if(info[@"Ssidd"]) { toSSID = info[@"SSID"]; + - } the } * returnSSID; $ }Panax Notoginseng -- (void) Viewdidload the { + [Super Viewdidload]; A theTemplabel=[[uilabel Alloc]initwithframe:cgrectmake ( -, +, $, +)]; +Templabel.textalignment=Nstextalignmentcenter; - [Self.view Addsubview:templabel]; $Nsdictionary *ifs =[self fetchssidinfo]; $NSString *ssid = [[IFS Objectforkey:@"SSID"] lowercasestring]; -templabel.text=SSID; - the}
Log information:
- 2013-06-05 21:39:14.357 wifinamedemo[9877:707] dici:{
- BSSID = "F4:ec:38:40:cc:e8";
- SSID = "Nice_apple";
- Ssiddata = <4e696365 5f417070 6c65>;
- }
- 2013-06-05 21:39:14.360 wifinamedemo[9877:707] Nice_apple
ARC version:
1- (ID) Fetchssidinfo {2Nsarray *ifs = (__bridge_transferID) cncopysupportedinterfaces (); 3NSLog (@"supported interfaces:%@", IFS); 4 IDinfo =Nil;5 for(NSString *ifnaminchIFS)6 { 7info = (__bridge_transferID) Cncopycurrentnetworkinfo ((__bridge cfstringref) Ifnam); 8NSLog (@"%@ =%@", Ifnam, info); 9 if(Info &&[Info count])Ten { One Break; A } - } - returninfo; the}
The effect is as follows:
IOS gets hotspot name and MAC address for WiFi
1 #import<SystemConfiguration/CaptiveNetwork.h>2 3NSString *ssid =@"Not Found";4 5NSString *macip =@"Not Found";6Cfarrayref MyArray =cncopysupportedinterfaces ();7 if(MyArray! =Nil) {8Cfdictionaryref mydict = Cncopycurrentnetworkinfo (Cfarraygetvalueatindex (MyArray,0));9 if(Mydict! =Nil) {TenNsdictionary *dict = (nsdictionary*) cfbridgingrelease (mydict); OneSSID = [Dict valueforkey:@"SSID"]; AMacIP = [Dict valueforkey:@"BSSID"]; - } - } theUialertview *av =[[Uialertview alloc] Initwithtitle:ssid - Message:macip - Delegate: Nil - Cancelbuttontitle:nil +Otherbuttontitles:@"OK", nil]; -[AV show];
"IOS" gets the WiFi name (i.e. SSID)