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

4

非越狱的iOS 7设备是否可以获取Wi-Fi RSSI值?我了解到MobileWiFi.framework和Apple80211函数,但如果我理解正确,它们需要越狱才能运行。

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


我需要WiFi信号强度。 - Pavlo Shadov
你搞定了吗?我尝试使用MobileWiFi.framework但没有成功。http://iphonedevwiki.net/index.php/MobileWiFi.framework - doxsi
1个回答

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;
}

@doxsi 这对我在一个受限制的(非越狱)设备上起作用了。 - Gad
能否分享一下你所采取的步骤?谢谢。 - doxsi

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