我是否正确使用 CNCopyCurrentNetworkInfo?

发布于 2024-11-02 03:32:51 字数 1071 浏览 0 评论 0原文

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

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

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);
    }
}

通过查看 NSLog 语句,在某些情况下,CNCopyCurrentNetworkInfo 似乎挂在 kCNNetworkInfoKeyBSSID 的旧数据上。

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

但是,如果我从打开一个 AP 开始运行此代码,就会正确获得该 AP 的 BSSID。然后,我打开第二个 AP,然后关闭第一个 AP(强制设备漫游到第二个 AP),日志语句仍然返回第一个 AP 的 BSSID(我已关闭该 AP,并且不可能连接到该 AP)。

有没有人比我有更多这方面的经验?我是否打算在调用之间手动刷新 CNCopyCurrentNetworkInfo 返回的值?

我已经在使用 Xcode 4 构建的运行 iOS 4.3 的第四代 iPod touch 和使用 Xcode 3.2.4 构建的运行 iOS 4.1 的 iPhone 4 上运行了此程序

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2024-11-09 03:32:51

我将为这个问题提供答案,因为它似乎偶尔会得到赞成票,并且可以找到解决方案。

简而言之,是的,这就是您应该如何使用 CNCopyCurrentNetworkInfo 的方式。这是 iOS 4 和 5 中的一个错误。如果您当前正在运行 iOS 6 beta,我建议您调查一下它是否仍然以这种方式运行,如果仍然如此,请向 Apple 报告。

我很幸运,因为我从事企业应用程序工作,并且能够通过调用私有 API 来获取这些信息。有关如何执行此操作的信息,我可能建议您查看此处:google 代码上的 iphone-wireless

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文