Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I using CNCopyCurrentNetworkInfo correctly?

I'm having some issues with the data returned by CNCopyCurrentNetworkInfo and was wondering if I'm doing something wrong.

I'm using the following code to display the BSSID of the currently connected Access Point:

NSArray* interfaces = (NSArray*) CNCopySupportedInterfaces();  

for (NSString* interface in interfaces) {

CFDictionaryRef networkDetails = CNCopyCurrentNetworkInfo((CFStringRef) interface);
if (networkDetails) {
    NSLog(@"all details: %@", (NSDictionary *)networkDetails);
    NSLog(@"BSSID: %@", (NSString *)CFDictionaryGetValue (networkDetails, kCNNetworkInfoKeyBSSID));
    CFRelease(networkDetails);
    }
}

By reviewing the NSLog statements it appears as though CNCopyCurrentNetworkInfo is hanging onto old data for kCNNetworkInfoKeyBSSID under certain circumstances.

I have two access points set up and I'm trying to obtain the BSSID of the currently connected AP. If I start with only one AP turned on it returns the correct BSSID. If I switch that AP off I get no BSSID (correct) and when I switch on the second AP and connect to it I am given the correct BSSID of the second AP.

However if I start with one AP turned on run this code and am correctly given the BSSID of that AP. I then turn on the second AP, then turn off the first (forcing the device to roam to the second AP) the log statements still return the BSSID of the first AP (which I have turned off and am not possibly connected to).

Does anyone have more experience with this than I've had? Am I meant to be manually flushing the values returned by CNCopyCurrentNetworkInfo between calls?

I am have run this on both a 4th gen iPod touch running iOS 4.3 built using Xcode 4 and an iPhone 4 running iOS 4.1 built using Xcode 3.2.4

like image 491
goawaygeek Avatar asked Apr 18 '11 02:04

goawaygeek


1 Answers

I'm going to provide an answer to this question because it seems to get the occasional up vote and could do with a solution.

Short version is that yes that is how you're supposed to use CNCopyCurrentNetworkInfo. This is a bug in iOS 4 and 5. If you're currently running an iOS 6 beta I would suggest investigating whether it still operates this way on there and reporting it to Apple if it does.

I was fortunate in that I work on enterprise applications and was able to gain this information using calls to private APIs. For info on how to do this I would probably recommend looking here: iphone-wireless on google code

like image 153
goawaygeek Avatar answered Nov 15 '22 05:11

goawaygeek