I don't understand the problem in the following line of code. I know that NSDictionary does not allow to insert nil objects so I am checking objects for nil before inserting them to NSDictionay, even after doing that crash appears.
-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
{
Request * logRequest = [self.requestLogUtil newRequest];
logRequest.requestParams = @{@"HTTP Method": ([request HTTPMethod] != nil ? [request HTTPMethod] : @""),
@"HTTP Headers": ([request allHTTPHeaderFields] != nil ? [request allHTTPHeaderFields] : @""),
@"Post Parameters": (request.HTTPBody != nil? [NSString stringWithUTF8String:[request.HTTPBody bytes]]: @""),
@"Query Parameters": ([request.URL query] != nil ? [request.URL query] : @"")
};
}
It crashes with following reason, but not every time.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
[NSString stringWithUTF8String:[request.HTTPBody bytes]]
? – Adam Wright