Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNetServiceBrowser delegate not called when searching

I got a really annoying problem. Im trying to search after a NSNetService (that i know exist). I've copied the example code from http://www.macresearch.org/cocoa-scientists-part-xxviii-bonjour-and-how-do-you-do into my own application. I can see (in the example program) that my service is created. But when i hit search, and start a NSNetServiceBrowser search, nothing happens. The delegate function newer gets called

 -(void)netServiceBrowser:(NSNetServiceBrowser *)aBrowser didFindService:(NSNetService *)aService moreComing:(BOOL)more {

I've been checking stuff like that my objects are still retained, and i can't see that anything is released (and i don't have GC on). Anybody got any ideas what to do? The code is exactly the same as in the example, only i got some other stuff around it (running a openGL window).

like image 483
Jonas Jongejan Avatar asked Aug 19 '10 22:08

Jonas Jongejan


1 Answers

This question is eons old (iOS 4/5 era?) so I'm not sure if this is the answer for you, but make sure that you're using NSNetServiceBrowser from the main thread of your application only.

(I can't remember if it also must be initialized on the main thread, or if it must just be initialized and called -search on from the same thread, or if it suffices to call -search from the main thread, but I had the exact same problem and in my case it was related to using a background thread in some way. Sorry for the vague answer.)

like image 80
TaylanKammer Avatar answered Oct 01 '22 22:10

TaylanKammer