国产探花免费观看_亚洲丰满少妇自慰呻吟_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"];}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 正定县| 炉霍县| 大名县| 蒙城县| 岱山县| 淅川县| 绥滨县| 龙陵县| 壤塘县| 金秀| 兴国县| 马山县| 财经| 北京市| 阿巴嘎旗| 崇阳县| 始兴县| 和平县| 定陶县| 宜城市| 竹溪县| 元朗区| 花莲市| 云龙县| 资源县| 富源县| 靖江市| 丰顺县| 青海省| 博乐市| 洪泽县| 台中市| 镇宁| 大英县| 宜州市| 河北区| 孝感市| 旬邑县| 达拉特旗| 抚松县| 泰和县|