I use the Reachability class to know if I have an internet connection available. The problem is when wifi is available but not internet, the - (NetworkStatus) currentReachabilityStatus
method take too much time.
my code:
Reachability* reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
The application "freeze" temporarily on the second line. How to define the maximum time for this waiting ?
I don't think so. But more importantly, I don't think you'd want to if you could (you may get false positives). Let Reachability run it's course.
If you look at the Reachability demo project, the notion isn't to invoke reachabilityWithHostName
and check currentReachabilityStatus
when you need the Internet. You invoke currentReachabilityStatus at during your app delegate's didFinishLaunchingWithOptions, set up a notification, and Reachability will tell you when the Internet connectivity has changed. I find that subsequent checks to currentReachabilityStatus
are plenty fast (regardless of connectivity) when I (a) setup reachability at startup; but (b) check for connectivity in a just-in-time manner.
And if you absolutely need to start your processing immediately, then the question is whether you can push that into the background (e.g. dispatch_async()
). E.g., my app retrieves updates from the server, but because that's happening in the background, neither me nor my user are aware of any delays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With