tags:

views:

211

answers:

1

Hello All:

I have an application which uses a web service to get data. Before getting data from the web service I check for network availability on the device by using the approach explained in "Reachabilty". But what it does it ping a server and depending upon the response it gives the status. But in my application I want to show different message to the user depending upon the network failure 1. Some time the network is not available on the device 2. Some time the pinged server is down

Can any body tell me how to differentiate between these two type of failure.

Thanks Ashwani

+1  A: 

Well, I guess you could instantiate a NSURL with your server address, and check if it fails with an error, or the connection succeeds:

- (NSError*)checkServer{
NSError *serverError;
NSString *command = [NSString stringWithFormat:@"http://192.168.0.1/"];

NSURLResponse *response;

NSURL *pathURL = [NSURL URLWithString:command];
NSURLRequest *request = [NSURLRequest requestWithURL:pathURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5.0];
NSData *theData =  [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&serverError];

if ([serverError code]) return serverError;

return nil;
}

Edit: You could take a look at the Reachability flags, they tell you more about the reachability status of a network node.

luvieere
Thanks Luvieere,I have tried this approach. But I am looking for an approach in which we can get the network status of the device, if network is available then only I want to make request to remote server. Any idea on that?
Ashwani K