国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巩留县| 陵水| 高要市| 大冶市| 那坡县| 永德县| 华安县| 汉阴县| 丹寨县| 手游| 泸水县| 通许县| 昭平县| 连城县| 阳泉市| 海丰县| 天门市| 马边| 邹平县| 云浮市| 出国| 万载县| 建瓯市| 孙吴县| 新化县| 泾川县| 舟曲县| 安乡县| 团风县| 新巴尔虎右旗| 梁山县| 湛江市| 邵阳市| 朝阳县| 吉林省| 长葛市| 上高县| 淮阳县| 高青县| 天门市| 安义县|