Find IP address in iphone

Posted by Ruchir Shah on Stack Overflow See other posts from Stack Overflow or by Ruchir Shah
Published on 2010-03-02T06:43:03Z Indexed on 2010/03/14 19:35 UTC
Read the original article Hit count: 331

Filed under:
|
|

Hi,

I want to find IP address in an application. I am able to find it. But, problem is, it works fins in iphone os 2.0 or so. But, in iphone os 3.0 it is giving me a warning:

warning: no '+currentHost' method found

warning: (Messages without a matching method signature)

I am using this code, and it works fine with os version 2.0.

-(NSString*)getAddress {
char iphone_ip[255];
strcpy(iphone_ip,"127.0.0.1"); // if everything fails
NSHost* myhost = [NSHost currentHost];
if (myhost)
{
    NSString *ad = [myhost address];
    if (ad)
        strcpy(iphone_ip,[ad cStringUsingEncoding: NSISOLatin1StringEncoding]);
}
return [NSString stringWithFormat:@"%s",iphone_ip]; 

}

How to find IP address in iphone os 3.0 or greater os version?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ip-address