views:

1787

answers:

1

I've incorporated Apple's Reachability sample into my own project so I know whether or not I have a network connection - if I don't have a network connection, I don't bother sending out and requests. I decided to go with the status notification implementation because it seemed easier to have the reachablity updated in the background and have the current results available immediately as opposed to kicking off a synchronous request whenever I want to make a network connection.

My problem is that I start getting false negatives when on an EDGE network - the phone has connectivity, but the app thinks this isn't the case. My understanding is you don't get a notification when an EDGE connection, so my assumption is that I lost and regained the connection at some point. Restarting the app is usually sufficient to see the network connection.

This isn't an optimal solution, so I was wondering if anybody else came across this problem and had any thoughts on a solutions.

(I don't know whether this applies to 3G as well; I'm running a first gen iPhone).

+11  A: 

Reachability notificataions didn't seem to be reliable for me either, for detecting Wi-Fi. So I just use polling instead. Checking every 5 seconds seems to do no harm.

- (void) checkReachability {
    BOOL connected = ([[Reachability sharedReachability] localWiFiConnectionStatus] == ReachableViaWiFiNetwork);

    // Do something...

    [self performSelector:@selector(checkReachability) withObject:nil afterDelay:5.0];
}
Chris Lundie
Thanks I was planning on incorporating Reachability today, so you probably saved my future self some time :)
Robert Gould
hey how do i use this class.I added Reachability.h and Reachability.m file and importedreachability.h file in my appDelegate now when i put your method in my appDelegate i get errors.
Rahul Vyas
The Reachability code has changed significantly in the past year. So, the above code will not work anymore.
Chris Lundie