The best way to accomplish this, not using Reachability
or any other API, is by creating a NSURL
and to try to receive data from it. For the bad connection I added a timeout of 20sec.
Like:
- (void)checkConnection //Run this on a side queue, never on a main queue
{ NSURL *checkURL = [NSURL URLWithString:@"http://www.apple.com"];
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:checkURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSData *data = [NSData dataWithContentsOfURL:lRequest];
if (data)
{
connected = YES;
}
else
{
connected = NO;
}
}
That would check if a specific website is reachable and set a timeout which indicates a slow network connection.
This code could have errors, as I haven't used/tried it yet! Comment this answer if there are any.