FAQ - aiXpertLab/OpenAI-ChatGPT-Practices GitHub Wiki
I cannot download an image.
Please check whether you are trying to access an image resource with "http" scheme. If so, you need to switch to "https" or disable ATS in your Info.plist.
Also, check the console or try to print the result
in the completion handler. If an error happens, you can get the reason there.
imageView.setImage(with: url) { result in
print(result)
}
The image cannot be cached and every time I have to download it again.
Kingfisher is using a hashed URL absolute string for the cache key by default. So if your URL changes, even only the query part or timestamp, Kingfisher will think that it is a new image that is not cached yet.
Does Kingfisher support server cache tags like E-Tag or Last-Modified?
No. Kingfisher's cache works by itself without supporting the server-side cache. The cacheKey
of the input source
value is used for searching and caching an image. Make sure you have different cache keys for different images.
If your server provides different images under the same URL, we suggest you ask your server to add a query to the URL for different versions. These URLs: https://example.com/image.png?v=1
and https://example.com/image.png?v=2
represents different images in Kingfisher (if you are not using customized ImageResource
and set cacheKey
yourself).
Can I load some special image format like WebP?
Yes. On iOS 14+, Kingfisher supports loading and displaying WebP images out of the box.
If you need to run on iOS 13 or older, you may need to implement your own ImageProcessor
and CacheSerializer
. It is also already done by some other libraries, for example, KingfisherWebP. For more discussion on this topic, search for "webp" in the issues.
Does Kingfisher support authentication with servers?
Yes. You could set up an ImageDownloadRequestModifier
and pass it in the option to modify the request header. It is useful when you are doing a basic HTTP authentication or any token-based authentication. If you are using some certification, please set authenticationChallengeResponder
of ImageDownloader
and implement your auth logic in the delegate method.
Can I just download or get the image without setting it to the image view?
Sometimes you are not doing UI things and just want the image. You could use KingfisherManager
for it:
KingfisherManager.shared.retrieveImage(with: url) { result in
// Do something with `result`
}
This will check the cache first, if the image is not cached yet, it will download it from the given URL. If you need more control of it, use ImageDownloader
and ImageCache
instead.