CFNetServiceCallBack example

492 Views Asked by At

I'm just starting to write a small iPhone/iPad app to browse network storage and want to search for available disks. I think I'm on the right track with CFNetService and associated functions but I'd love a bit of help at this point:

Would someone mind posting an example of a CFNetServiceCallBack function as in the "MyBrowseCallBack" that's in the "gServiceBrowserRef" setup in the following example from Apple's doc's:

static Boolean MyStartBrowsingForServices(CFStringRef type, CFStringRef domain) {

 CFNetServiceClientContext clientContext = { 0, NULL, NULL, NULL, NULL };

 CFStreamError error;

 Boolean result;



 assert(type != NULL);



 gServiceBrowserRef = CFNetServiceBrowserCreate(kCFAllocatorDefault, MyBrowseCallBack, &clientContext);

 assert(gServiceBrowserRef != NULL);



 CFNetServiceBrowserScheduleWithRunLoop(gServiceBrowserRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);



 result = CFNetServiceBrowserSearchForServices(gServiceBrowserRef, domain, type, &error);

 if (result == false) {



     // Something went wrong so lets clean up.

     CFNetServiceBrowserUnscheduleFromRunLoop(gServiceBrowserRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);         CFRelease(gServiceBrowserRef);

     gServiceBrowserRef = NULL;



     fprintf(stderr, "CFNetServiceBrowserSearchForServices returned (domain = %d, error = %ld)\n", error.domain, error.error);

 }



 return result;

}

I am reading the documentation, honest! It's just I'm personally finding it hard going to research the topic (my first time dipping into network coding) and would just like a little nudge in the right direction. Even if it's only an example that shows the signature of the function required for "MyBrowseCallBack"

1

There are 1 best solutions below

0
On

I found the answer - typically right under my nose!

void clientCB (CFNetServiceBrowserRef browser,CFOptionFlags flags,CFTypeRef domainOrService,CFStreamError* error,void* info)
{
NSLog(@"Found browser: %@",domainOrService);
CFStreamError anError;
if ((flags && kCFNetServiceFlagMoreComing) != kCFNetServiceFlagMoreComing) {
    NSLog(@"That'll be all...");
    CFNetServiceBrowserStopSearch(browser, &anError);
    return;
}
return;

}

I think I'm barking up the wrong tree though, it's probably not going to get me any closer to getting a file directory of the remote disk....