Accessing IP Address with NSHost

先试试这整个:
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在其他地方声明

你可能感兴趣的:(Access)