2016-11-09 16 views
1

我有這個應用程序在Objective C中編碼。在我的應用程序中有一個場景,我想列出所有可用的Wi-Fi網絡可用於連接我的iPad 。當我搜索它時,我發現私有API是唯一的選擇。有沒有其他方式可以顯示所有可用的Wi-Fi網絡?我找到了一種顯示已連接的WiFi連接名稱和詳細信息的方法。但我想要我的應用程序中的Wi-Fi可用連接列表。提前致謝。快樂編碼。在我的應用程序中的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]; 
      [email protected]""; 
      _textfield.hidden=YES; 
     } 
     else 
     { 
      _textfield.textColor=[UIColor blackColor]; 
      _textfield.text=wifiName; 
      _textfield.hidden=NO; 
+0

那麼爲什麼不能你通過這些你找到的API,你面臨的任何問題? – vaibhav

+0

我還沒有嘗試過,但從互聯網上看到,使用它可能會導致應用程序被拒絕。 – ALEX

+0

我建議你在實現這種功能之前檢查一下,你的問題看起來像是基於觀點的,我們不能在這裏看到任何可能的代碼。 – vaibhav

回答

0

ü喜歡它的完成here

或U可以參考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 
可以列出本地WiFi

linkthis也可以是有幫助的

相關問題