我想在我的应用程序中获取所有可用的 wifi 网络。我怎样才能继续这样做。当我使用 CNCopyCurrentNetworkInfo 类时,只连接了网络。但我需要显示我的 iPhone 范围内的所有可用网络。
最佳答案
这是来自 here 的示例。 请记住,如果您想将应用程序推送到应用程序商店,您的应用程序将被拒绝。您无法以苹果商店接受的方式检索所有列表。
#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());
}
关于ios - 在 iOS 中显示所有可用的 wifi 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28854220/