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

首頁 > 系統 > iOS > 正文

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

2019-10-21 18:47:17
字體:
來源:轉載
供稿:網友

導入頭文件

#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"];}

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


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双鸭山市| 夏邑县| 定兴县| 肥乡县| 阳信县| 中江县| 东方市| 安化县| 盐山县| 云和县| 威海市| 苏尼特左旗| 徐汇区| 巩留县| 乌拉特后旗| 蒙自县| 北票市| 蓬安县| 边坝县| 兰州市| 常德市| 阳高县| 翁牛特旗| 松阳县| 邵武市| 穆棱市| 沈丘县| 沙雅县| 阳春市| 鸡泽县| 雷山县| 合阳县| 淮北市| 霍林郭勒市| 临漳县| 元朗区| 华宁县| 礼泉县| 若尔盖县| 肇州县| 靖边县|