The Miotz The Miotz - 4 months ago 26
iOS Question

iOS Objective-c: how to set and ImageView from an URL

Evening, I'm trying to set an ImageView.image (an IBOutlet in this case) with an image downloaded from the web.

I've already ridden a lot of questions about this in stack overflow.

And I've found this common answer:

NSURL *url = [NSURL URLWithString:@""];

NSData *data = [NSData dataWithContentsOfURL:url];

NSLog(@"imageData: %@", data);

UIImage *image = [UIImage imageWithData:data];

NSLog(@"image: %@", image);

self.imageView.image = image;

But of course in my case does not work. My logs are always null.

Can you please tell me which is the problem?


I believe you are trying to run it on iOS 8 +

Please add this to your info.plist


And everything should be fine :)

WHY ??

iOS 8 onwards http is not allowed you have to use either https or add exception to your info.plist :)