Want to check is Internet is available or not-available before calling any WEB-SERVER.
I used the Reachiablity which provided by apple to check the internet is on or off. I added this two files into my project. Reachability.h and Reachability.m
In ViewController.h
-(BOOL)connected;
and ViewController.m its Implementation.
-(BOOL)connected{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
return networkStatus != NotReachable;
}
before calling webserver making an condtion
if([self connection] == true){
// Do call web server.
}
else {
// Alert message print. // Please check internet connection.
}
When running the application in both case with WIFI ON or OFF with MACBOOKPRO "Simulator" or on Device. Its always returns true condition.
Please let me know, what should i need to do properly for making reachablity work.
I am using Xcode 6.0.1 IOS SDK 8.0.
@ALL Thank In Advance.
Why bother? If there's no network connection, you'll get a perfectly good error back from your attempt. Reachability is useful for knowing when a connection has returned, if you had network jobs queued up, but it's pointless to check before every web call.
You need error handling code anyway, because a missing connection is only one of several reasons a request could return an error. In this case reachability is adding extra code for no benefit, which is true of most uses I've seen.