本文介绍了如何使用 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 为零.

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

...然后你可以使用你得到的字典 (myDict) 上的 kCNNetworkInfoKeySSID 来找出 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 热点名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 05:56