问题说明
有的网络图片链接中有逗号, 使用kingfisher 加载不出来。
http://img3.imgtn.bdimg.com/it/u=3731532511,3143059206&fm=26&gp=0.jpg
解决方案:
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)
}
}
网友评论