我正确使用CNCopyCurrentNetworkInfo吗? [英] Am I using CNCopyCurrentNetworkInfo correctly?

查看:416
本文介绍了我正确使用CNCopyCurrentNetworkInfo吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CNCopyCurrentNetworkInfo返回的数据有一些问题,并且想知道我是否做错了。



我正在使用以下代码来显示当前连接的接入点的BSSID:

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

for(接口中的NSString *接口){

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

通过查看NSLog语句,看起来好像是CNCopyCurrentNetworkInfo在某些情况下挂起到kCNNetworkInfoKeyBSSID的旧数据。



我设置了两个接入点,我正在尝试获取当前连接的AP的BSSID。如果我开始只打开一个AP,它将返回正确的BSSID。如果我关闭那个AP我没有BSSID(正确),当我打开第二个AP并连接到它时,我得到了第二个AP的正确BSSID。



但是,如果我从一个AP启动开始运行此代码并正确地给出该AP的BSSID。然后我打开第二个AP,然后关闭第一个AP(强制设备漫游到第二个AP),日志语句仍然返回第一个AP的BSSID(我已关闭并且可能无法连接)。 / p>

有没有人比我更有经验?我打算在调用之间手动刷新CNCopyCurrentNetworkInfo返回的值吗?



我在使用Xcode 4构建的运行iOS 4.3的第4代iPod touch上运行了这个运行iOS 4.1的iPhone 4使用Xcode 3.2.4构建

解决方案

我将提供这个问题的答案,因为它似乎偶尔投票,可以解决问题。



短版本是肯定的,你应该如何使用CNCopyCurrentNetworkInfo。这是iOS 4和5中的一个错误。如果您目前正在运行iOS 6测试版,我会建议调查它是否仍然以这种方式运行并向Apple报告。



我很幸运,因为我处理企业应用程序,并且能够使用私有API调用获取此信息。有关如何执行此操作的信息,我建议您在此处查看: Google手机上的iphone-wireless


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

解决方案

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

这篇关于我正确使用CNCopyCurrentNetworkInfo吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆