Objective-C可以通过编程方式登录wifi网络吗? [英] Can objective-C log into a wifi network programmatically?

查看:165
本文介绍了Objective-C可以通过编程方式登录wifi网络吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,在您的硬盘驱动器上,您有本地的公共Wi-Fi名称和密码集合,例如在咖啡店中找到的那些名称和密码.然后您进入从未有过的咖啡店,OSX应用程序将可用的wifi网络与列表中的一个相匹配并登录.目标c可行吗?

Imagine that on your hard drive you had a local collection of public wi-fi names and passwords such as those that are found in coffeeshops. And you enter a coffeeshop where you have never been before, and an OSX app matches an available wifi network as one on the list and signs you in. Is this possible with objective c?

推荐答案

您可以使用

You can use CoreWLAN to scan, connect, disconnect and etc. to WiFi networks. Here is a short and simplified example how to scan for networks and connect to a network:

#import <CoreWLAN/CoreWLAN.h>

CWInterface *cwInterface = [[CWInterface alloc] initWithInterfaceName:@"en1"]; // specify here the WiFi interface
NSError *err = nil;

// get all networks
NSSet *networksSet = [cwInterface scanForNetworksWithName:nil error:&err];
NSArray *allNetworks = [networksSet allObjects];

CWNetwork *selectedNetwork;

// check if one of the scanned networks SSIDs matches network with SSID "network_name"
for (CWNetwork *network in allNetworks) {

    // perhaps you will have another for here, looping over NSDictionary with network name as key and password as value
    if ([network.ssid isEqualToString:@"network_name"]) {
        selectedNetwork = network;
    }
}

// finally connect to the selected network
[cwInterface associateToNetwork:selectedNetwork password:@"network_password" error:&err];

// you can also disconnect as well
[cwInterface disassociate];

您可以查看 CoreWLANWirelessManager 作为更广泛的版本例子.

You can check CoreWLANWirelessManager as a more extensive example.

这篇关于Objective-C可以通过编程方式登录wifi网络吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆