I want to get all available wifi networks in my application. How can I proceed to do that. When I used the CNCopyCurrentNetworkInfo class , got only connected network. But I need to display all available networks in my iPhone range.
Asked
Active
Viewed 250 times
0
-
possible duplicate of [Find available wi-fi networks](http://stackoverflow.com/questions/10317028/find-available-wi-fi-networks) – Anbu.Karthik Mar 04 '15 at 12:15
1 Answers
1
Here's an example from here. Keep in mind that your app will get rejected if you want to push your app to the app store. You can't retreive the list of all in a way it will be accepted on apple store.
#include <MobileWiFi.h>
static WiFiManagerRef _manager;
static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token);
int main(int argc, char **argv)
{
_manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
CFArrayRef devices = WiFiManagerClientCopyDevices(_manager);
if (!devices) {
fprintf(stderr, "Couldn't get WiFi devices. Bailing.\n");
exit(EXIT_FAILURE);
}
WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
WiFiManagerClientScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
WiFiDeviceClientScanAsync(client, (CFDictionaryRef)[NSDictionary dictionary], scan_callback, 0);
CFRelease(devices);
CFRunLoopRun();
return 0;
}
static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token)
{
NSLog(@"Finished scanning! networks: %@", results);
WiFiManagerClientUnscheduleFromRunLoop(_manager);
CFRelease(_manager);
CFRunLoopStop(CFRunLoopGetCurrent());
}

michal.ciurus
- 3,616
- 17
- 32