Friday, June 21, 2013

NSNetService hostName example in Objective C (iOS).


NSNetService hostName

Returns the host name of the computer providing the service.

- (NSString *)hostName

Return Value of [NSNetService hostName]
The host name of the computer providing the service. Returns nil if a successful resolve has not occurred.

NSNetService hostName example.
I believe that "hows-testing" is the host name of the computer, not the name of the service. Instead, you want to look at the hostName attribute:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@", [ns hostName]);
}
You should probably also examine the port attribute, and include it in the URL, if the port is something other than the default for that protocol (80 for HTTP)

End of NSNetService hostName example article.