"IOS" gets the WiFi name (i.e. SSID)

Source: Internet
Author: User
Tags bssid

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:

    1. 2013-06-05 21:39:14.357 wifinamedemo[9877:707] dici:{
    2. BSSID = "F4:ec:38:40:cc:e8";
    3. SSID = "Nice_apple";
    4. Ssiddata = <4e696365 5f417070 6c65>;
    5. }
    6. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.