iOS 7(非越狱)Wi-Fi RSSI值

时间:2014-08-12 07:58:34

标签: ios ios7 iphone-privateapi rssi

是否有可能在非越狱的iOS 7设备上获得Wi-Fi RSSI值?我阅读了有关MobileWiFi.framework和Apple80211函数的内容,如果我理解正确,它们在没有越狱的情况下无效。

我不想在AppStore上发布我的应用程序,因此允许使用PrivateAPI。

1 个答案:

答案 0 :(得分:1)

我无法找到原始帖子,但是它适用于运行iOS 7.1的监狱设备(不能在iOS 8上运行):

#include <dlfcn.h>

-(NSDictionary *)currentWiFiInfo
{
   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 *error;

   if (libHandle == NULL && (error = dlerror()) != NULL)  {
      NSLog(@"%s", 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"];

   return infoDict;
}