Determining when an EDGE connection comes back after a dropout on an iPhone

删除回忆录丶 提交于 2019-12-03 02:52:08

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/181485/determining-when-an-edge-connection-comes-back-after-a-dropout-on-an-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!