国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS獲取當前連接的WiFi以及IP地址

2020-07-26 02:51:58
字體:
來源:轉載
供稿:網友

導入頭文件

#import <ifaddrs.h>#import <arpa/inet.h>#import <SystemConfiguration/CaptiveNetwork.h>

核心代碼:

+ (nullable NSString*)getCurrentLocalIP{  NSString *address = nil;  struct ifaddrs *interfaces = NULL;  struct ifaddrs *temp_addr = NULL;  int success = 0;  // retrieve the current interfaces - returns 0 on success  success = getifaddrs(&interfaces);  if (success == 0) {    // Loop through linked list of interfaces    temp_addr = interfaces;    while(temp_addr != NULL) {      if(temp_addr->ifa_addr->sa_family == AF_INET) {        // Check if interface is en0 which is the wifi connection on the iPhone        if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {          // Get NSString from C String          address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];        }      }      temp_addr = temp_addr->ifa_next;    }  }  // Free memory  freeifaddrs(interfaces);  return address;}
+ (nullable NSString *)getCurreWiFiSsid {  NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();  NSLog(@"Supported interfaces: %@", ifs);  id info = nil;  for (NSString *ifnam in ifs) {    info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);    NSLog(@"%@ => %@", ifnam, info);    if (info && [info count]) { break; }  }  return [(NSDictionary*)info objectForKey:@"SSID"];}

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 图木舒克市| 宜宾县| 新乡县| 绥棱县| 高阳县| 宣威市| 义乌市| 山阳县| 扎囊县| 德令哈市| 东宁县| 平邑县| 顺昌县| 铅山县| 南汇区| 黄大仙区| 洱源县| 苍南县| 九龙城区| 麻城市| 汾西县| 瓮安县| 青浦区| 长乐市| 灵川县| 文山县| 丰原市| 宜兰市| 乡城县| 西畴县| 鄂州市| 灵石县| 曲松县| 将乐县| 华蓥市| 红桥区| 武夷山市| 罗山县| 永兴县| 光泽县| 香河县|