Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternatives to NSHost in iPhone app
    text
    copied!<p>I'm currently using this code</p> <pre><code> NSHost *host = [NSHost hostWithAddress:hostname]; if (host == nil) { host = [NSHost hostWithName:hostname]; if (host == nil) { [self setMessage:@"Invalid IP address or hostname:"]; return; } } </code></pre> <p>to retrive my IP Address for a networking app I'm working on, however I'm aware that NSHost is a private API that will be rejected. Can anyone help me with working this code to produce the same results without using NSHost? I'm not really sure where to start.</p> <p>EDIT:</p> <p>Following suggestions that seem damn near perfect below I've added this code into my app in the place of the code above</p> <pre><code> Boolean result; CFHostRef hostRef; CFArrayRef addresses; NSString *hostname = @"www.apple.com"; hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname); if (hostRef) { result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed if (result == TRUE) { addresses = CFHostGetAddressing(hostRef, &amp;result); } } if (result == TRUE) { NSLog(@"Resolved"); } else { NSLog(@"Not resolved"); } </code></pre> <p>I've removed the 4th line (as I have this information from elsewhere already) but I get errors being based around CFHostRef being undeclared. How would I resolve that? It seems to be my only big hurdle, as other errors are only based upon the lack of being able to see hostRef after that. EDIT: Scratch that I also get kCFHostAddresses undeclared.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload