0

I'm trying to retrieve an image from a url but for some reason it will not not display the image

if let url = NSURL(string: "http://cdn.businessoffashion.com/site/uploads/2014/09/Karl-Lagerfeld-Self-Portrait-Courtesy.jpg") { if let data = NSData(contentsOfURL: url) { print("work") imageUIView.image = UIImage(data: data) } else { print("dontwork") } } 
2
  • Not having any issues. Image is getting retrieved properly. Post the code where you're trying to display the image. Commented May 26, 2016 at 4:26
  • Is there any kind of error? I tried with your code and working fine here. Have you make proper IBOutlet connection with imageView? Commented May 26, 2016 at 5:40

1 Answer 1

1

If you are targeting iOS 9.0 or OS X v10.11, you may be running into Apple's App Transport Security. Running your code while targeting these operating system versions, the following output will be displayed int console:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

Apple now requires you to only access files via https or to allow non-https (ie. http) exceptions via info.plist.

If you haven't already, I'd suggest updating your info.plist.

You can do this on a per domain basis, or allow arbitrary loading of non-https url.

For example, update your info.plist with the following keys/values:

enter image description here

If this is your issue, once your info.plist is updated, your code should work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.