Accessing IP Address with NSHost

Posted on 2012-03-13 13:49  无忧consume  阅读(294)  评论(0编辑  收藏  举报
先试试这整个:
NSHost* myhost =[NSHost currentHost]; 
NSString *ad = [myhost address]; 
再试试:
-(void) getIPWithNSHost{
   
NSArray*addresses =[[NSHost currentHost] addresses];

for(NSString*anAddress in addresses){
   
if(![anAddress hasPrefix:@"127"]&&[[anAddress componentsSeparatedByString:@"."] count]==4){
         stringAddress
= anAddress;
       
break;
   
}else{
        stringAddress
=@"IPv4 address not available";
   
}
}
       
//NSLog (@"getIPWithNSHost: stringAddress = %@ ",stringAddress);    

}

//NSString *stringAddress; is declared else where在其他地方声明

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes