I'm getting an image over HTTP, using NSURLConnection, as follows -
NSMutableData *receivedData;
- (void)getImage {
self.receivedData = [[NSMutableData alloc] init];
NSURLConnection *theConnection = // create connection
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
UIImage *theImage = [UIImage imageWithData:receivedData];
}
Usually it works just fine, but sometimes I'm seeing this get logged - : Corrupt JPEG data: premature end of data segment
At this point, the image does not completely render. I'll see maybe 75% of it, and then the lower right hand corner is a grey box.
Any ideas on how to approach fixing this? Am I constructing my image improperly?