IPConfiguration apple80211Open() 在 iOS8 上崩溃

IPConfiguration apple80211Open() crashes on iOS8

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

使用 Xcode 6.1.1 和 iPhone6+ ios 8.1.3

下面的代码在 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 returns NULL,并且 - 崩溃(您应该始终检查 return 值,您知道)。

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

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

Apple80211 API 已在某些时候从 IPConfiguration 中删除,例如iOS 11 和 12,但在 iOS 13 回来了,截至今天,这些方法仍然存在并且在 iOS 13.4.1 中工作。我期望的是您无法使其工作的原因可能是因为 iOS 8 您需要 com.apple.wlan.authentication 权利,如前所述 here.

目前有一个 sneaky way 可以在应用程序中使用此权利(供您自己使用),但它将在 iOS 13.5 中停止工作。