1
votes

using iphone sdk 3.1.2

I use the following code to monitor whether my app has an internet connection. I need to either get notifications or poll so my app always has the latest status.

hostReach = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
[hostReach startNotifer];

then when i get a notification i use these functions to let me know the network status

NetworkStatus netStatus = [hostReach currentReachabilityStatus];
BOOL connectionRequired= [hostReach connectionRequired];

I've found that if i unplug the power cable on my Netgear Router my app correctly knows its lost its internet connection. However when i plug the power back in, my app although it gets notifications from the Reachability callback the netStatus returned by

[hostReach currentReachabilityStatus]

never is equal to ReachableByWifi which is what i want to know if the internet is available through the WiFI connection).

Even if i have a timer every 30secs to call

[hostReach currentReachabilityStatus]

it still does not return ReachablebyWifi even when clearly the router is all started up and internet is definitely available. This was a worst case situation which i thought would work.

On another note if i only pull out the phone line connection and leave the router powered on (ie wifi signal still present0 my app does not get notified the internet connection is down.

How to get over these issues?

2

2 Answers

1
votes

A few months ago I found someone who wrote a better Reachability implementation. You can find it at http://blog.ddg.com/?p=24. My company uses it in our apps and it is much more robust than the Apple sample.

0
votes

I experienced the same. In my opinion the Reachability class is flakey and should be considered Sample Code. Someone should rewrite that whole thing based on feedback from the community.