如何使用CaptiveNetwork获取当前的WiFi热点名称 [英] How do I use CaptiveNetwork to get the current WiFi Hotspot Name

查看:263
本文介绍了如何使用CaptiveNetwork获取当前的WiFi热点名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前连接的Wi-Fi热点的名称,例如BT OpenZone

I need to get the name of the currently connected Wi-Fi hotspot, e.g. "BT OpenZone"

我被告知可以通过 CaptiveNetwork 专门CNCopyCurrentNetworkInfo

I have been told it can be done with CaptiveNetwork specifically CNCopyCurrentNetworkInfo

我的代码到目前为止:

#import <SystemConfiguration/CaptiveNetwork.h>
...

// Get the dictionary containing the captive network infomation
CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(kCNNetworkInfoKeySSID);

// Get the count of the key value pairs to test if it has worked
int count = CFDictionaryGetCount(captiveNtwrkDict);
NSLog(@"Count of dict:%d",count);

当代码在WiFi热点的设备上运行时, captiveNtwrkDict 是nil。

When the code runs on a device in a WiFi hotspot the captiveNtwrkDict is nil.

有人设法让它工作吗?我不能在CaptiveNetworks上找到许多文档或任何示例代码示例...任何帮助将非常感激。

Has anyone managed to get it working? I cant find much documentation or any example code examples on CaptiveNetworks... any help would be much appreciated.

推荐答案

找出哪些网络可用,然后将它们传递到CNCopyCurrentNetworkInfo。例如:

You need to find out which networks are available, and then pass them into CNCopyCurrentNetworkInfo. For example:

CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));

...然后你可以使用你回​​来的字典的kCNNetworkInfoKeySSID(myDict)找出SSID。不要忘记适当地释放/管理内存。

...and you can then use the kCNNetworkInfoKeySSID on the dictionary you've got back (myDict) to find out the SSID. Don't forget to release/manage memory appropriately.

这篇关于如何使用CaptiveNetwork获取当前的WiFi热点名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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