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
-
1any update on this for iOS 8 ? I tried https://github.com/devinshively/wifiAssociate, it doesn't works on iOS 8. – divyum Aug 11 '15 at 10:09
-
No, I haven't tested it on iOS 8. – almas Aug 11 '15 at 16:45
2 Answers
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);

- 7,090
- 7
- 33
- 49
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.

- 1,595
- 10
- 19
-
I'm not very good at reverse engineering, so even if I get header files (they are available for download) I just don't know how to use them. Those methods take some parameters (structs), and I don't know what they are. That is why I'd like to have a ready-to-use code sample in obj-c – almas Jul 30 '12 at 17:13
-
Well you can't see the implementation of the methods, they're called private (and undocumented) for a reason. The names and parameters are usually a good indicator of what the function does. Look up any structs that you aren't sure of and if you really need to, you can use mobile substrate to write a tweak to hook these methods and find more information about what is being passed to them and what they're returning. – John Corbett Jul 30 '12 at 17:23