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