I\'m using Bonjour with an NSNetService to publish a server from my iPhone. It all works as expected, I can browse the pages I\'m serving etc. However, on the iPhone I want
The [[NSProcessInfo processInfo] hostName]
method was not useful for me for two reasons:
The following code from http://iphoneappcode.blogspot.com/2012/05/how-to-get-device-ipaddess-in-iphone.html worked best for me, always returning the local host name with sensitive case:
+ (NSString *) hostname
{
char baseHostName[256];
int success = gethostname(baseHostName, 255);
if (success != 0) return nil;
baseHostName[255] = '\0';
#if !TARGET_IPHONE_SIMULATOR
return [NSString stringWithFormat:@"%s.local", baseHostName];
#else
return [NSString stringWithFormat:@"%s", baseHostName];
#endif
}
You can get the hostname via [[NSProcessInfo processInfo] hostName] without resolving the netservice you just published.
Check this link out:
This says your error it was still trying to resolve the service:
https://developer.apple.com/library/IOs/documentation/Cocoa/Reference/Foundation/Classes/NSNetService_Class/index.html#//apple_ref/c/tdef/NSNetServicesError