Search code examples
iosswiftiphonesdwebimage

SDWebImage not works with Spanish Alphabets into Image name iOS Swift


I am using SDWebImage latest updated version & it works good so far. Recently I found one issue which started causing the crash issue into my Application.

I observed that if Image URL having a Alphabet in Spanish then its unable to download & generates the nil exception. This later on coverts into the crash issue.

Here how I used it :

    cell.imgView.sd_setImage(with: URL(string: imString)!) { (img, error, type, url) in
        cell.imgView.image  = img?.resizeTopAlignedToFill(newWidth: collectionView.frame.size.width)
                cell.imgView.contentMode = .top
    }

This kind of URL where image name is having Spanish Alphabet do not works :

https://test.com/uploads/image_watermark/cloacacaña.PNG

Important Note :

  • I have done enough research on it & found that any language which contains special alphabets which are not normal like English Alphabets causing the same issue.

Please help me out if someone has found any solution to resolve this issue.

Any suggestions will be highly appreciated.


Solution

  • That is not a proper URL. Try changing your url string by adding utf encoding.

    cell.imgView.sd_setImage(with: URL(string: imString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)!) { (img, error, type, url) in
    cell.imgView.image  = img?.resizeTopAlignedToFill(newWidth: collectionView.frame.size.width)
    cell.imgView.contentMode = .top }