我在哪里可以找到iOS Obj-C代码来扫描并连接到wifi(私有API)

alm*_*mas 7 iphone-privateapi wifi ios

我需要一个示例obj-c代码来扫描并连接到wifi.私有API没关系,我不会将应用程序发布到appStore.我发现cydia中的应用程序称为"WiFiFoFum",可以扫描和连接,遗憾的是我无法找到该应用程序的源代码.谁知道我在哪里可以找到该代码?谢谢

alm*_*mas 7

在这里找到答案:http://code.google.com/p/iphone-wireless/issues/detail?id = 20

它在我的iPhone 4 v5.1.1上完美运行.我能够扫描并连接到网络.您可以在这里下载项目https://github.com/devinshively/wifiAssociate

这是一个引用:

Apple80211Associate仍然有效(至少在3.1.2上).在iPhone OS 2和3之间,框架已更改名称,因此您应该按以下方式绑定您的函数:

void *airportHandle;
int     (*Apple80211Open)(void *);
int     (*Apple80211BindToInterface)(void *, NSString *);
int     (*Apple80211Close)(void *);
int     (*Apple80211Info)(void *, NSDictionary**);
int     (*Apple80211Associate)(void *, NSDictionary*, void *);
int     (*Apple80211Scan)(void *, NSArray **, void *);

libHandle       = dlopen("/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager", RTLD_LAZY);
Apple80211Open                          = dlsym(libHandle, "Apple80211Open");
Apple80211BindToInterface       = dlsym(libHandle, "Apple80211BindToInterface");
Apple80211Scan                          = dlsym(libHandle, "Apple80211Scan");
Apple80211Close                         = dlsym(libHandle, "Apple80211Close");
Apple80211Info                          = dlsym(libHandle, "Apple80211GetInfoCopy");
Apple80211Associate                     = dlsym(libHandle, "Apple80211Associate");
Run Code Online (Sandbox Code Playgroud)

从v2到v3的最重要变化是SCAN_RSSI_THRESHOLD参数(用于扫描功能).它使用一个正数,远离它应该具有的物理dB
,现在它需要信号的dB.如果您使用它,您可以将其设置为-100:这是一个剪切的代码(从我的代码中挑选出来,因此未经测试):

void *airportHandle;

NSArray *keys = [NSArray arrayWithObjects:@"SCAN_RSSI_THRESHOLD", @"SSID_STR", nil];
NSArray *objects = [NSArray arrayWithObjects:[NSNumber numberWithInt:-100], ssid, nil];

NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSArray *found;


int openResult = Apple80211Open(&airportHandle);
NSLog(@"Openning wifi interface %@", (openResult == 0?@"succeeded":@"failed"));

int bindResult = Apple80211BindToInterface(airportHandle, @IF_NAME);

int scanResult = Apple80211Scan(airportHandle, &found, params);

NSDictionary *network;

// get the first network found
network = [found objectAtIndex:0];
int associateResult = Apple80211Associate(airportHandle, network,NULL);

Apple80211Close(airportHandle);
Run Code Online (Sandbox Code Playgroud)