I want to confirm that an URL is accessible/reachable before calling it. I knew reachabilityWithHostName
method can help me to do this task. I used the following code to know about URL reachability. But it does not works.
Reachability *connection = [Reachability reachabilityWithHostName:@"stackoverflow.com"];
[connection startNotifier];
NetworkStatus netStatus = [connection currentReachabilityStatus];
The netStatus
always returns NotReachable
(means 0
) value even everything is fine.
Notes:
- I don't want to use any other third party reachability classes
- I downloaded the current
Reachability
class from here - I placed the above lines of code in my sample project's
viewDidLoad
method - The last strange thing that I wonder is, If I set a breakpoint in the first line and run the code step by step by tapping step over button in Xcode, the
netStatus
returns correct value ?!?!?!?!
Help needed!! Confused!!