title: NSNetServiceBrowser/Bonjour issues on iOS
body: <p>I'm using Bonjour (NSNetServiceBrowser, to be precise) over WiFi in an app I'm developing for an iOS project I've been working on.</p>
  
  <p>However, despite noting the issues raised in the excellent response at <a href="https://stackoverflow.com/questions/1273368/why-does-nsnetservicebrowser-find-unpublished-services-in-iphone-os">Why does NSNetServiceBrowser find unpublished services in iPhone OS?</a> I am still encountering a number of difficulties with NSNetSericeBrowser.</p>
  
  <p>My set-up is as follows:</p>
  
  <ul>
  <li>Working with iPads running iOS 4.5.3.</li>
  <li>Using an AirPort Express as an access point/router.</li>
  <li>Running dns-sd -B _serviceName on my Mac connected to the network works fine -- that is to say, all calls to publish and stop are immediately reflected on the desktop.</li>
  </ul>
  
  <p>However, I've experienced the following issues:-</p>
  
  <ol>
  <li>Services that are published for a long time (approx. 15mins+) tend to not get removed on clients <strong>even though they disappear from the Mac!</strong> (i.e. didRemoveService doesn't get called).</li>
  <li>Sometimes services that are published are not seen by others on the network, <strong>even though they appear on the Mac!</strong> (i.e. didFindService not called) -- this is probably related to the points 3/4 below... whereby if the app starts running (and searching) before the iPad is connected to the network, then it doesn't search the new network properly.</li>
  <li>What happens if a device changes network after <em>publishing</em> a service? I've found that Bonjour does <strong>not</strong> re-publish the service on the new network -- how can one force this to happen?</li>
  <li>What happens if a device changes network while <em>searching for services</em>? I've found that this causes problems too, and it tends to result in the session not being found (didFindService not called).</li>
  </ol>
  
  <p>The problems I've been having are weird, because Bonjour works 90% of the time... it's just that 10% that are ruining the reliability of my app! The annoying this is that ALL of the above issues can be resolved by double-pressing the home button and force-closing the app, and then re-running it. After running it again, it ALWAYS finds the correct sessions or publishes properly.</p>
  
  <p>One way to sidestep this issue would be to tear-down and restart the NSNetServiceBrowser whenever the wireless network is changed... but this seems very messy and unnecessary. The frustrating thing is that Bonjour is a high-level API without any real options to tweak and test.</p>
  
  <p>Any ideas how I might be able to sort out issues 1-4?</p>
  
  <p>Thanks!</p>