-1

I am using Alamofire (for Swift) & AFNetworking (for Objective c) and I am facing the same issue with both of them.

Here is a sample URL

"https://static.toiimg.com/photo/msid-61516774/61516774.jpg?59422"

pretty basic URL but when I try to setImage it fails to load the image. When I try to load the same URL in Google Chrome it loads easily, but it fails to load when I try it on Safari. It simply downloads the image.

Can anyone suggest what I can do to handle such URI's?

I am doing nothing fancy in my code. Pretty basic Alamofire/Afnetworking

setImageWithUrl:PlaceHolderImage: method for both of them.

Thanks in advance.

  • 1
    Show the setImage code – TheValyreanGroup Nov 06 '17 at 13:04
  • If you use the corresponding method of AFNetworking for instance that use a completionHandler (like `setImageWithURLRequest:placeholderImage:success:failure:`), you'll see why it fails. It's giving me this: "Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: image/jpg" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: image/jpg,". You may start digging up on this, the content-type of the response may be wrongly set. – Larme Nov 06 '17 at 13:06
  • To add information on @Dix answer, SDWebImage seems to check the data (https://github.com/rs/SDWebImage/blob/master/SDWebImage/NSData%2BImageContentType.m) instead of relying only on headers. – Larme Nov 06 '17 at 13:20

2 Answers2

1

It is the issue from your server where your image is there.

Otherwise if you try with different url like,

 [_myImageView setImageWithURL:[NSURL URLWithString:@"https://static.pexels.com/photos/236636/pexels-photo-236636.jpeg"] placeholderImage:nil];

then it is working fine but if I try with your url I am getting NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824) and nw_coretls_read_one_record tls_handshake_process: [-9824] errors in log.

It may possible than your TLS version is outdated in your server side!

Solve the issue from server and your code will work!

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
0

Swift 3

 func loadImage() {

    let url = NSURL(string: "https://static.toiimg.com/photo/msid-61516774/61516774.jpg?59422")!

    let task = URLSession.shared.dataTask(with: url as URL) { (responseData, responseUrl, error) -> Void in
        if let data = responseData{

            DispatchQueue.main.async(execute: { () -> Void in
                self.yourImageView.image = UIImage(data: data)
            })
        }
    }

    task.resume()
}

Hope it works.