title: Getting the HostName of a Remote iOS Device with NSNetService
body: <p>After more than a few hours of searching, I got in what looks like a dead end. In this case, all that I am trying to do, is to get all the iOS Devices of the network with Bonjour. I did so like this</p>
  
  <pre><code>self.serviceBrowser = [[NSNetServiceBrowser alloc] init];
  [self.serviceBrowser setDelegate:self];
  [self.serviceBrowser searchForServicesOfType:@"_apple-mobdev2._tcp." inDomain:@"local."];
  </code></pre>
  
  <p>This works fine, though what I get is the following:</p>
  
  <pre><code>local. _apple-mobdev2._tcp. [MAC ADDRESS HERE]
  </code></pre>
  
  <p>I tried to resolve the connection by using the sync port (62078), since service.port returns -1.</p>
  
  <pre><code>for (NSNetService *service in self.services) {
      NSLog(@"%@", service);
          NSNetService *newService = [[NSNetService alloc] initWithDomain:service.domain type:service.type name:service.name port:62078];
          [newService setDelegate:self];
          [newService resolveWithTimeout:30];
  }
  </code></pre>
  
  <p>This in its own turn calls netServiceWillResolve: with no problem at all, but, it doesn't make it to netServiceDidResolveAddress:</p>
  
  <p>But neither does this fail. netService:didNotResolve: isn't called either, I believe it is just waiting for a response to be resolved.</p>
  
  <p>To support this claim, once it did make it to the method and actually [service hostName]; did return Yanniss-iPhone, but that happened at a completely random time that I had left the Mac App running for around half an hour. What could have invoked this to run? Or does anyone know of a different way to get the hostName of the remote device? The other answers do not answer my question, since I am looking for the hostName of the remote device, not of the Mac device. </p>
  
  <p>Relative to that, I've found that when you kill and restart iTunes, along with iTunes Helper, the very log I mentioned below is sent again. Which is why I believe the correct log was an iTunes related event. Any help is very much appreciated!</p>