gpt4 book ai didi

objective-c - 使用 CNCopyCurrentNetworkInfo 的问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:54 24 4
gpt4 key购买 nike

我正在使用以下代码检索 iPod 连接的 WiFi 网络的 SSID。

NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
NSLog(@"%s: %@ => %@", __func__, ifnam, info);
if (info && [info count]) {
break;
}
[info release];
}

有时此代码未返回我的设备连接的网络的正确 SSID。关于为什么未正确检索 SSID 的任何指示? CNCopyCurrentNetworkInfo 包是否依赖于设备的 iOS 版本?

谢谢。

最佳答案

  1. 将 SystemConfiguration.framework 添加到项目。

  2. import < SystemConfiguration/CaptiveNetwork.h >

  3. CFArrayRef myArray = CNCopySupportedInterfaces();
    CFStringRef interfaceName = CFArrayGetValueAtIndex(myArray, 0);
    CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(interfaceName);
    NSDictionary *dict = ( NSDictionary*) captiveNtwrkDict;
    NSString* ssid = [dict objectForKey:@"SSID"];
    NSLog(@"%s ssid : %@",__FUNCTION__, [ssid description]);
  4. 对于 iOS 12 及更高版本,您必须从功能中启用它。

Important To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. Documentation link

关于objective-c - 使用 CNCopyCurrentNetworkInfo 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com