Where do I find iOS Obj-C code to scan and connect to wifi (private API)

你离开我真会死。 提交于 2019-11-26 19:48:21

问题


I need a sample obj-c code that scans and connects to wifi. Private API is ok, I'm not going to publish the app to appStore. I found the app in cydia called "WiFiFoFum" that can scan and connect, unfortunately I can't find the source code of that app. Anybody knows where I can find that code? Thanks


回答1:


Found the answer here: http://code.google.com/p/iphone-wireless/issues/detail?id=20

It works perfectly fine on my iPhone 4 v5.1.1. I'm able to scan and connect to networks. You can download the project here https://github.com/devinshively/wifiAssociate

Here is a citation:

Apple80211Associate is still working (at least on 3.1.2). Between the iPhone OS 2 and 3, the framework has changed name, so you should bind your functions as following:

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");

The most significant change from v2 to v3 is SCAN_RSSI_THRESHOLD parameter (used for the scan function). It use to take a positive number, far from the physical dB it should have been
and now it takes the dB of the signal. If you make use of it, you can set it to -100: Here is a code snipped (cherry picked from my code, so untested as is):

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



回答2:


Objective-C is compiled, so you can't just get the source code of programs like in a scripting language. You can check to see if "WiFiFoFum" is open source, and you might be able to download the source from the author's github. Otherwise you can look at the private frameworks in the /System/Library/PrivateFrameworks directory and dump the header files from them using class-dump-z like this

$ class-dump-z -H <private framework>

without the angle brackets of course.

edit:

just checked, doesn't look like it's open source.



来源:https://stackoverflow.com/questions/11725553/where-do-i-find-ios-obj-c-code-to-scan-and-connect-to-wifi-private-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!