I wanted to check is device connoted to internet, and to check for my webpage.
So I found this answer: How to check for an active Internet connection on iOS or OSX?
In it code example was:
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
So I puted:
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.weborcode.com/apps/gdjesumojepare/"];
What was not working, it would say that there is no internet connection, even when I was on internet.
So by some miracle I manage to understand that it is only working with domain name weborcode.com or www.weborcode.com.
But not with the the full path of the resource.
Is there any war to make it work with the full path of the resource ?
If you re-asses your code, you are calling reachabilityWithHostname
, this will only check the hostname, that consist of two part, local part i.e www
and the domain part i.e weborcode.com
, So if you are trying to check a specific URL page then i would suggest you to look into NSURLConnection
Simple example:
NSURL *myURL = [NSURL URLWithString: @"www.example.org/apps/gdjesumojepare/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: myURL];
NSURLResponse *response;
NSError *error;
NSData *pageData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
If pageData
return nil, this means that the webpage is down, If you receive back a non-nil pageData, this mean there is connectivity. response and error will tell you what the server responded to you.