Its because you are doing webcall and getting data from server
response = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/jsonTest.php"]];
but there is no active connection so you will get nothing in response variable. and when you pass that response to jsonarray can't parse it. so the error occurred.i would suggest that before doing webcall check for the internet connection. if there is active connection then only you can make call to server. you can check internet connection like this:
- (BOOL) connectedToNetwork
{
// Create zero addy
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
// Recover reachability flags
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
SCNetworkReachabilityFlags flags;
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
CFRelease(defaultRouteReachability);
if (!didRetrieveFlags)
{
return NO;
}
BOOL isReachable = flags & kSCNetworkFlagsReachable;
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
return (isReachable && !needsConnection) ? YES : NO;
}
for this code to work add library:
SystemConfiguration.framework
and import this to your class
#import <SystemConfiguration/SystemConfiguration.h>
Hope it Helps!!