views:

27

answers:

0

Hi,

in my iPhone app I list some hosts that publish themselves via bonjour (NSNetService). The user is able to save those hosts to a favorites list.

What I want to do is to check if those hosts are reachable via LAN or if they are offline. To do this I am observing ReachabilityChangedNotifications in my ViewController:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:@"kNetworkReachabilityChangedNotification" object:nil];

and create an instance of the Reachability class provided by Apple in the Reachability Sample for each favorite:

    Reachability *favReach = [[Reachability reachabilityWithHostName:[fav hostName]] retain];
    [favReach startNotifier];
    [fav setOnline:([favReach currentReachabilityStatus] != NotReachable)];
    [reachArray addObject:favReach];
    [favReach release];

fav is an object containing properties to store the hostName (taken from the NSNetService), some other values and a BOOL if the host is online or offline (used to output a string in a UITableView row corresponding to this favorite).

The problem is, that reachabilityChanged is never called, even if I turn off the host. This leads to my question: Is it even possible to use the NSNetService hostname (something like MY-PC.localdomain.) as a parameter of reachabilityWithHostname? What could be my mistake here?

Thanks a lot for your help.