我正确使用 CNCopyCurrentNetworkInfo 吗?

Am I using CNCopyCurrentNetworkInfo correctly?(我正确使用 CNCopyCurrentNetworkInfo 吗?)

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

问题描述

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

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

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

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

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

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

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

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.

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

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).

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

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?

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

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.

简短的版本是,是的,这就是您应该使用 CNCopyCurrentNetworkInfo 的方式.这是 iOS 4 和 5 中的一个错误.如果您当前运行的是 iOS 6 测试版,我建议您调查它是否仍然以这种方式运行,如果是,则向 Apple 报告.

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.

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

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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:我正确使用 CNCopyCurrentNetworkInfo 吗?

基础教程推荐