I am checking for server connection with the code below, however 'connection' is always TRUE..
I know that 'initWithRequest:delegate:' is deprecated: and it is recommended to use NSURLSession instead, however I'd prefer continuing using it for simplicity as NSURLSession seems much more complex to implement.
Any advice to make it work?
NSURL *url = nil;
NSMutableURLRequest *request = nil;
NSString *getURL = [NSString stringWithFormat:@"%@?TEST=%@",URL, str];
url = [NSURL URLWithString: getURL];
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request addValue: @"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection) //Always true!!!
{
mutableData = [NSMutableData new];
NSLog(@"SERVER CONNECTION OK");
}
else
{
NSLog(@"NO SERVER CONNECTION");
}