ios iPhone SDK 能否获取当前连接的Wi-Fi SSID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/339089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can the iPhone SDK obtain the Wi-Fi SSID currently connected to?
提问by danimal
In the iPhone SDK I don't see the same SCDynamicStore
used on Mac OS X to get the SSID name that your wireless network is currently connected to isn't available.
在 iPhone SDK 中,我没有看到SCDynamicStore
Mac OS X 上用于获取无线网络当前连接到的 SSID 名称的方法不可用。
Is there a way to get the SSID name that the iPhone is currently connected to?
有没有办法获取 iPhone 当前连接的 SSID 名称?
I see some apps do it (Easy Wi-Fi for AT&Tfor one) but I can't find how it's done in the iPhone SDK docs. A private or unpublish method would be acceptable just as a proof of concept (although I know that likely wouldn't make it to the AppStore).
我看到一些应用程序这样做(其中一个是用于 AT&T 的 Easy Wi-Fi),但我在 iPhone SDK 文档中找不到它是如何完成的。私有或未发布方法作为概念证明是可以接受的(尽管我知道这可能不会出现在 AppStore 中)。
回答by Nate
This is now possible (iOS 4.1+) via the Captive Network API.
现在可以通过Captive Network API实现(iOS 4.1+)。
See an example of how to use it on this similar question.
请参阅有关如何在此类似问题上使用它的示例。
This is not a private API.
这不是私有 API。
回答by danimal
After digging around I found the anser to this. There are unpublished APIs in the Preferences framework. For examples of this one can look at the Stumbler codehosted on Google Code.
在挖掘之后,我找到了这个答案。Preferences 框架中有未发布的 API。有关此示例,可以查看托管在 Google Code 上的Stumbler 代码。
I filed a radar with Apple (#6407431/OpenRadar version) that was marked as a duplicate of #5814810). If you want this officially supported then please also file a radar at bugreport.apple.com.
我向 Apple 提交了一份雷达(#6407431/ OpenRadar 版本),该雷达被标记为与 #5814810 重复。如果您希望得到官方支持,请同时在bugreport.apple.com 上提交雷达报告。
Update: The above Stumbler code is for 1.x revision iPhone OS SDK. For iPhone OS 2.0 and beyond developers will have to look in PrivateFrameworks/Apple80211.Framework and all that implies.
更新:上述 Stumbler 代码适用于 1.x 版 iPhone OS SDK。对于 iPhone OS 2.0 及更高版本,开发人员必须查看 PrivateFrameworks/Apple80211.Framework 以及所有这些内容。
回答by MSA
Try this code,
试试这个代码,
#import <SystemConfiguration/CaptiveNetwork.h>
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSDictionary *ssidList = (__bridge NSDictionary*)myDict;
NSString *SSID = [ssidList valueForKey:@"SSID"];