ios - 在 iOS 中显示所有可用的 wifi 网络

标签 ios networking xcode6 wifi

我想在我的应用程序中获取所有可用的 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/

相关文章:

linux - 为什么增加网络缓冲区大小不能减少丢包?

swift - 如何在 iOS 中列出可发现的蓝牙设备和已配对的设备,快速使用哪种方法?

ios - Swift - 带有 Objective-C 选择器 '*()' 的方法 '*' 与具有相同 Objective-C 选择器的父类(super class) '*' 的 'NSObject' 的 getter 冲突

ios - 在 objective-c 中仅附加一次字符串

iOS:如何在选项卡栏 Controller 的不同 View 之间共享数据

ios - Rails两次转义换行符

scala - 如何在play框架中使用akka、scala、websockets实现 'Private Chat'模块?

ios - xcode ios6 中的 iAd 填充率设置在哪里?

python - 使用 Python 在 LAN 上发布和查找服务的正确方法

ios - Google Analytics 未在 Swift 中初始化