【问题标题】:Display all avialable wifi networks in iOS在 iOS 中显示所有可用的 wifi 网络
【发布时间】:2015-03-04 12:13:48
【问题描述】:

我想在我的应用程序中获取所有可用的 wifi 网络。我该如何继续这样做。当我使用 CNCopyCurrentNetworkInfo 类时,只有连接的网络。但我需要显示我的 iPhone 范围内的所有可用网络。

【问题讨论】:

标签: ios networking xcode6 wifi


【解决方案1】:

这是来自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());
}

【讨论】:

    猜你喜欢
    • 2022-09-28
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    相关资源
    最近更新 更多