Am I using CNCopyCurrentNetworkInfo correctly?(我正确使用 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 吗?
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01