Kingfisher加載不出帶逗號的圖片url

問題說明

有的網絡圖片鏈接中有逗號, 使用kingfisher 加載不出來。

http://img3.imgtn.bdimg.com/it/u=3731532511,3143059206&fm=26&gp=0.jpg

參考相關問題1
參考相關問題2

解決方案:

let modifier = AnyModifier { request in
    var r = request
    // replace "Access-Token" with the field name you need, it's just an example
    r.setValue("APP/iOS", forHTTPHeaderField: "User-Agent")
    return r
}

let url = URL(string: <YOUR_URL>)

let iView = <YOUR_IMAGEVIEW>

iView.kf.setImage(with: url, options: [.requestModifier(modifier)]) { (image, error, type, url) in
    if error == nil && image != nil {
        // here the downloaded image is cached, now you need to set it to the imageView
        DispatchQueue.main.async {
            iView.image = image
        }
    } else {
        // handle the failure
        print(error)
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章