I'm developing an application, and I'm getting the data of JSON from the Database using MAMP PRO for now. This is the Code:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.8/ArabLineDatabase/GetSocialNetworkCount.php"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.8/ArabLineDatabase/GetSocialNetworkCount.php"]];
JsonData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
NSLog(@"Connecting.....GetSocialNetworkCount.M");
}
else
{
NSLog(@"Can't connect.....GetSocialNetworkCount.M");
}
The problem is whenever there is no internet or i close the server so it will not be reachable my application crash, and i get an error that the JSON Data is nil
How i can prevent that?