ios - IP 配置 apple80211 Open() 在 iOS8 上崩溃

标签 ios objective-c iphone network-programming

我正在尝试读取 iPhone WIFI 连接到 AP 的 RSSI。

在 iPhone6+ ios 8.1.3 上使用 Xcode 6.1.1

以下代码在 apple80211Open() 处崩溃并在 iOS 8 上获取 EXC_BAD_ACCESS (code=1, address= 0)。(代码适用于 iOS 7.1)

这适用于不适用于 Apple Store 的应用程序 -- 仅用于临时分发。

============================================= ==================

void *libHandle;
   void *airportHandle;

   int (*apple80211Open)(void *);
   int (*apple80211Bind)(void *, NSString *);
   int (*apple80211Close)(void *);
   int (*apple80211GetInfoCopy)(void *, CFDictionaryRef *);

   NSMutableDictionary *infoDict = [NSMutableDictionary new];
   NSDictionary * tempDictionary;
   libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);

   char *dlerror_error;

   if (libHandle == NULL && (dlerror_error = dlerror()) != NULL)  {
      NSLog(@"%s", dlerror_error);
   }

   apple80211Open = dlsym(libHandle, "Apple80211Open");
   apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");
   apple80211Close = dlsym(libHandle, "Apple80211Close");
   apple80211GetInfoCopy = dlsym(libHandle, "Apple80211GetInfoCopy");

   apple80211Open(&airportHandle);
   apple80211Bind(airportHandle, @"en0");

   CFDictionaryRef info = NULL;

   apple80211GetInfoCopy(airportHandle, &info);

   tempDictionary = (__bridge NSDictionary *)info;

   apple80211Close(airportHandle);

   [infoDict setObject:(tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] ? (tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] : @"0" forKey:@"RSSI"];

   [infoDict setObject:tempDictionary[@"BSSID"] ? tempDictionary[@"BSSID"] : @"null" forKey:@"BSSID"];

   [infoDict setObject:tempDictionary[@"SSID_STR"] ? tempDictionary[@"SSID_STR"] : @"null" forKey:@"SSID"];

   [infoDict setObject:tempDictionary[@"RATE"] ? tempDictionary[@"RATE"] : @"0" forKey:@"SPEED"];

最佳答案

那是因为 Apple 从 IPConfiguration 中删除了 80211 框架。找不到符号,dlsym 返回 NULL,并且 - 崩溃(您应该始终检查返回值,您知道)。

首先,这是一个私有(private)框架。在新版本的 iOS (8+) 中,它已被弃用,支持 MobileWifi,并使用权利(和 XPC)以便让/usr/libexec/wifid 完成所有工作。

本文有更多详细信息:http://newosxbook.com/articles/11208ellpA.html

关于ios - IP 配置 apple80211 Open() 在 iOS8 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29044036/

相关文章:

objective-c - 在 Macos High Sierra 上创建和绑定(bind)套接字

iphone - 找不到符号 : _OBJC_CLASS_$_UIPopoverController

ios - 关闭导航 View Controller

ios - UIImageView 没有更新

iphone - cocoa 服务器问题

ios - 将 CLLocationCooperatives2D 转换为 NSValue

iphone - 尝试创建 pList 但它没有被创建

ios - 检查哪个注释标注正在打开

iphone - GameCenter GKMatchmakerViewController 自动匹配不起作用,expectedPlayerCount 始终为 1,解决方案?

ios - 在属性检查器或 Controller 代码中启用用户交互?