Why this image link not showing up in UIimageView in ios?

Viewed 202

Why this image link not showing up in UIimageView in ios ?

var url = URL(string: "https://bill.ps/uploads/32065621a012e53f749c15b0a8468d71swift_file5486.png")

Code

func fetchImage(_ photoURL: URL?) { 
    guard let imageURL = photoURL else { return } 
    DispatchQueue.global(qos: .userInitiated).async { 
        do { 
            let imageData: Data = try Data(contentsOf: imageURL) 
            DispatchQueue.main.async { 
                let image = UIImage(data: imageData)
                print(image)
            } 
        } catch { 
            print("Unable to load data: (error)")
        } 
    } 
}

Image Link

3 Answers

The issue in the image itself not in the link or in your code, I've tried the same image and It's not appearing at all in many cases, but at the same time another image appeared, if you can, try to change it and it will work, I even downloaded it and tried to put it manually in the assets file but doesn't work as well, check the images below:

1- Adding the image locally in the assets enter image description here

2- the image isn't appearing in the running

enter image description here

First of all, you should really use URLSessionDownloadTask for these things.

Anyway, the image link seems to be working, so there should not be any issue in fetching and displaying it.

Here are the things you can check -

  1. Is the print inside catch being executed?
  2. What is printed when you do print(image) after you receive data for it?
  3. Is your UIImageView instance visible on screen and has non-zero width & height values at run time?

You must make sure about point #3 at run time using View Hierarchy Debugger.

I checked the issue with backend developer , its related to WAF header on api server .

WAF block requests with missing in header.

Related