我有这个用Objective C编码的应用程序。在我的应用程序中有一个场景,我想列出可用于连接我的iPad的所有可用Wi-Fi网络。当我用谷歌搜索它时,我发现私有API是唯一的选择。有没有其他方法可以显示所有可用的Wi-Fi网络?我找到了一种方法来显示已连接的WiFi连接名称和详细信息。但我希望我的应用程序中的Wi-Fi可用连接列表。提前致谢。快乐的编码。
NSString *wifiName = nil;
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs)
{
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
NSLog(@"info:%@",info);
if (info[@"SSID"])
{
wifiName = info[@"SSID"];
if(([wifiName rangeOfString:@"WA"].location == NSNotFound))
{
_textfield.textColor=[UIColor redColor];
_textfield.text=@"";
_textfield.hidden=YES;
}
else
{
_textfield.textColor=[UIColor blackColor];
_textfield.text=wifiName;
_textfield.hidden=NO;
答案 0 :(得分:0)
你可以列出本地Wifi,就像它完成here
一样或者您可以参考this问题
最有趣的部分是
struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
其中
NSString *name = [NSString stringWithUTF8String:temp_addr->ifa_name];
NSString *addr = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; // pdp_ip0
en0 is of type IEEE80211
en3 is of type Ethernet
en1 is of type Ethernet
en2 is of type Ethernet
bridge0 is of type Bridge
pdp_ip0 is of type cellular
utun0 is of type vpn
ipv4 is of type Ethernet
ipv6 is of type Ethernet
ap is of type accesPoint