Question

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).

Was it helpful?

Solution

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];
}

OTHER TIPS

There is a nice reachability example on the net. it works wonderfully well: http://servin.com/iphone/iPhone-Network-Status.html

But you see, when I try to use it my own way, it just bombs.

Tried to implement it using:

NSString *sCellNetwork;     
 NSString *sNetworkReachable;  

if (flags & kSCNetworkFlagsReachable || flags & kSCNetworkReachabilityFlagsIsWWAN)

{do it} 

 else {
   Network fail alert; 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top