data parameter is nil error when checking internet connectivity

Posted by JSA986 on Stack Overflow See other posts from Stack Overflow or by JSA986
Published on 2012-10-24T22:42:08Z Indexed on 2012/10/24 23:00 UTC
Read the original article Hit count: 171

Filed under:
|
|

When launching my app it checks if user is subscribed. If it dosent detect an internet connection it crashes with the error:

Failed to retrieve subscription with error 'The Internet connection appears to be offline.' and responseString: (null)*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

.m

  [self getPath:path
   parameters:parameters
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          if (![responseObject isKindOfClass:[NSDictionary class]])
          {
              failureBlock(@"Invalid response received");
              return;
          }
          NSDictionary *subscriptionDict = (NSDictionary *)responseObject;
          if (subscriptionDict[@"error"] == nil)
          {
              DebugLog(@"Successfully retrieved subscription");
              successBlock(subscriptionDict);
          }
          else
          {
              failureBlock(responseObject);
          }
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          DebugLog(@"Failed to retrieve subscription with error '%@' and responseString: %@", error.localizedDescription, operation.responseString);
          id responseObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                              options:0
                                                                error:nil];
          failureBlock(responseObject);
      }];
}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios