1

I'm using NSURLConnection to load an image (of size 1.2 mb) from server. What I'm doing is in delegate I'm assigning my imageView (its an UIImageView) with received image. So it looks like downloading.

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    UIImage *image = [UIImage imageWithData:receivedData];
    imageView.image = image;
    image = nil;
}

During the time XCode prints NSLog with the following message.

<Error>: ImageIO: JPEG Corrupt JPEG data: premature end of data segment

I know its the message of corruted bytes i'm making an UIImage and then assing it to imageView.

Is there anyway to stop XCode to write this message on behalf of me? I've to do so as I need to show user that image is downloading.

I've checked some answers that on checking bytes!! But its not my solution as I already know why this happens?, I just want to stop XCode to print this on be half of me.

Edited

Data would corrupted while Downloading using of NSURLConnection.

Thanks!

7
  • What's printing here in NSLog ? Is it Image ? its seems very lack question.. Commented Oct 9, 2012 at 5:50
  • So image appears partly? Like in the old times with slow internet connection, images appeared line by line? Not sure why are you doing it like that, it's better to rely on connectionDidFinishLoading an show activity indicator instead. Commented Oct 9, 2012 at 6:02
  • @MANIAK_dobrii, Good comment answer! What if there will be 50 of images can be load at the same time, and I don't just relay on UIActivityIndicator and progressCounter as I'm already doing so. I want to make it friendly that user get attention that yes, images are coming!! :). Commented Oct 9, 2012 at 6:05
  • Btw it only shows the nslog while you test it on simulator on real device does it run well? if yes why you bother about the nslogs ? It will never noted by any app user on device lol :) Commented Oct 9, 2012 at 6:26
  • @Wolvorin, :D Yes that's I can feel, that no-user will get so!! But when I run it in device it still prints it. You know as developer a single message would jump us on our chair!!! :D Commented Oct 9, 2012 at 6:31

1 Answer 1

3

EDIT: If u have more images then its better u use SDWebImage for loading images

Firstly recieve whole data of image for that use this delegates:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    if (!receivedData)
    {
        receivedData = [NSMutableData data];
    }

    [receivedData appendData:data];

    NSLog(@"Receiving data... Length: %d", [receivedData length]);
}

Now data received completely this method will be called:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
  UIImage *image = [UIImage imageWithData:receivedData];
  if(image) 
    imageView.image = image;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I know this thing, but I can't implement in that way! Read question again.
Read the answer again. You're trying to make the image before you've downloaded it all, this is always going to give you an error. Use a progress view or activity indicator to show that your download is progressing.
I'm already did this before. What if there will be 50 of images can be load at the same time, and I don't just relay on UIActivityIndicator and progressCounter as I'm already doing so. I want to make it friendly that user get attention that yes, images are coming!! :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.