IPhone SDK: Bonjour name & NSNetService! = Published name?

In my iPhone application, I publish bonjour service and using the following delegate method:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@.%@", [ns name], [ns domain]);
}

The "name" property returns the name of the device "How Testing", which is valid. However, when I use Safari to discover available services, the name "hows-testing" is http://hows-testing.local.:somePortNumber .

Why is the published name different from what is reported by NSNetService? How to display the actual name of the published service? Assuming for some reason there is no way to get the published name from an object, how do I define it myself? I understand that it is based on the name of the device, but what are the substitution rules? Remove the apostrophes, replace the dashes with spaces ... anything else? What about special characters?

+3
source share
1 answer

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]);
}

, port URL-, - , (80 HTTP).

+1

Source: https://habr.com/ru/post/1747206/


All Articles