The method is coded incorrectly. It passes in
-(NSInteger)expectedContentLength; directly into NSMutableData's
-initWithCapacity: method.
The first method can return -1 based on the server that is being accessed
and whether or not it returned a content length header. If no header is
present, the return value is as per the documents:
Return Value
The receiver’s expected content length, or NSURLResponseUnknownLength if
the length can’t be determined.
This constant is -1. When passed into the initWithCapacity: method this
causes an NSInvalidArgumentException to be raised, and the application crashes.
Here is the corrected code:
- (void)connection:(NSURLConnection *)_connection
didReceiveResponse:(NSURLResponse *)response
{
if (data != nil)
[data release];
NSInteger contentLength = [response expectedContentLength];
if (contentLength < 0) {
contentLength = 0;
}
data = [[NSMutableData alloc] initWithCapacity:contentLength];
}
Original issue reported on code.google.com by db%quarr...@gtempaccount.com on 30 Jan 2009 at 2:02
Original issue reported on code.google.com by
db%quarr...@gtempaccount.com
on 30 Jan 2009 at 2:02