ios获取本机IP
//首先加入头文件
创新互联建站主要从事成都做网站、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务禄丰,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
#include
#include
//获取本机IP
-(NSString *)getDeviceIPAdress
{
NSString *address = @"error";
structifaddrs *interfaces = NULL;
structifaddrs *temp_addr = NULL;
int success = 0;
success = getifaddrs(&interfaces);
if (success == 0)
{
temp_addr = interfaces;
while (temp_addr != NULL)
{
if (temp_addr->ifa_addr->sa_family == AF_INET)
{
if ([[NSStringstringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{
address = [NSStringstringWithUTF8String:inet_ntoa(((structsockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
freeifaddrs(interfaces);
return address;
}
名称栏目:ios获取本机IP
文章网址:http://azwzsj.com/article/ggcoih.html