iOS UIImageView dataWithContentsOfURL returning empty

Posted by user761389 on Stack Overflow See other posts from Stack Overflow or by user761389
Published on 2012-10-18T10:26:17Z Indexed on 2012/10/18 11:01 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I'm trying to display an image from a URL in a UIImageView and I'm seeing some very peculiar results. The bit of code that I'm testing with is below

imageURL = @"http://images.shopow.co.uk/image/user_dyn/1073/32/32";
imageURL = @"http://images.shopow.co.uk/assets/profile_images/default/32_32/avatar-male-01.jpg";

NSURL *imageURLRes = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:imageURLRes];
UIImage *image = [UIImage imageWithData:imageData];

NSLog(@"Image Data: %@", imageData);

In it's current form I can see data in the output window which is what I'd expect. However if comment out the second imageURL so I'm referencing the first I'm getting empty data and therefore nil is being returned by imageWithData. What is possibly more confusing is that the first image is basically the same as the second but it's been through a PHP processing script. I'm nearly certain that it isn't the script that's causing the issue because if I use this instead

imageURL = @"http://images.shopow.co.uk/image/product_dynimg/389620/32/32"

the image is displayed and this uses the same image processing script. I'm struggling to find any difference in the images that would cause this to occur. Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios