iOS 7(非越狱)Wi-Fi RSSI值 [英] iOS 7 (non-jailbreak) Wi-Fi RSSI value

查看:136
本文介绍了iOS 7(非越狱)Wi-Fi RSSI值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在非越狱的iOS 7设备上获得Wi-Fi RSSI值?我读过有关MobileWiFi.framework和 Apple80211 的函数,如果我理解正确,他们就不会越狱。

Is it possible to get Wi-Fi RSSI value on non-jailbroken iOS 7 device? I read about MobileWiFi.framework and Apple80211 functions and if I understand correct they don't work without jailbreak.

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

I don't want to publish my app on AppStore, so PrivateAPI is allowed.

推荐答案

我找不到原来的帖子,但它在运行iOS 7.1的被监禁设备上对我有用(在iOS 8上不起作用):

I can't find the original post from where this was taken but it worked for me on a jailed device running iOS 7.1 (doesn't work on 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;
}

这篇关于iOS 7(非越狱)Wi-Fi RSSI值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆