Can't display image from url using Kingfisher

天涯浪子 提交于 2021-01-07 01:33:04

问题


I imported Kingfisher

 import UIKit
 import Kingfisher
    

This is my simple code to can explain the problem
Creating an imageView and trying display image from URL

class ViewController: UIViewController {

    @IBOutlet weak var image:UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let rawstring = "https://apis.baytelhekma.com/zinzo/public/storage/" + #"products\November2020\eUWwRjNCYCdHUjGIQiJk.png"#
        
        let url = URL(string: rawstring)
        image.kf.setImage(with: url)

       
    }


}

回答1:


Please check your url again as I've tried another url and it works fine, you can check it:

import UIKit
import Kingfisher
class ViewController: UIViewController {

    @IBOutlet weak var image:UIImageView!
    let rawstring = "https://i.insider.com/5e820b04671de06758588fb8?width=700&format=jpeg&auto=webp"

        override func viewDidLoad() {
            super.viewDidLoad()
            
            
            let url = URL(string: rawstring)
            image.kf.setImage(with: url)

           
        }

}

or you can make url like this if it helped:

 let rawstring = "https://apis.baytelhekma.com/zinzo/public/storage/products/November2020/eUWwRjNCYCdHUjGIQiJk.png"



回答2:


The problem is incorrect url, your're using \ in address.

So

let rawstring = "https://apis.baytelhekma.com/zinzo/public/storage/" + #"products\November2020\eUWwRjNCYCdHUjGIQiJk.png"

provides

https://apis.baytelhekma.com/zinzo/public/storage/products\November2020\eUWwRjNCYCdHUjGIQiJk.png

which is incorrect url


Changing it to

let rawstring = "https://apis.baytelhekma.com/zinzo/public/storage/" + #"products/November2020/eUWwRjNCYCdHUjGIQiJk.png"#

or simply to

let rawString = "https://apis.baytelhekma.com/zinzo/public/storage/products/November2020/eUWwRjNCYCdHUjGIQiJk.png"

will fix your issue



来源:https://stackoverflow.com/questions/65112827/cant-display-image-from-url-using-kingfisher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!