IPConfiguration apple80211Open()在iOS8上崩溃

5
我正在尝试读取iPhone连接到AP的WIFI信号强度(RSSI)。
我使用的是带有iOS 8.1.3的iPhone6+和Xcode 6.1.1。
下面的代码在iOS 8上崩溃,并在apple80211Open()处出现EXC_BAD_ACCESS (code=1, address=0) 的错误。(该代码可在iOS 7.1上工作。)
这是一款非苹果商店应用——仅限于adhoc分发。
=================================================================
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"];

我有同样的问题... 有什么想法吗?谢谢! - Alberto Juarez
2个回答

4
由于苹果从IPConfiguration中删除了80211框架,因此找不到符号,dlsym返回NULL,并且会崩溃(你应该始终检查返回值,你知道的)。首先,这是一个私有框架。在新版本的iOS(8+)中,它已被弃用,改为使用entitlements(和XPC)来使/usr/libexec/wifid完成所有工作。关于这个问题的更多详细信息,请参见本文:http://newosxbook.com/articles/11208ellpA.html

如果苹果确实将其删除,那么它现在又回来了,在iOS 13.4.1中,Apple80211方法位于IPConfiguration内部。 - malhal

0

Apple80211 API在某些时候被从IPConfiguration中移除,例如iOS 11和12,但在iOS 13中回归了,并且截至今天,在iOS 13.4.1中这些方法仍然存在且可用。我认为你无法让它工作的原因可能是自iOS 8以来,你需要com.apple.wlan.authentication授权,如此处所述。

目前有一种诡秘的方法可以在应用程序中使用此授权(供您自己使用),但它将在iOS 13.5中停止工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接