ImageDownloaderDelegate
public protocol ImageDownloaderDelegate : AnyObject
Protocol of ImageDownloader
. This protocol provides a set of methods which are related to image downloader
working stages and rules.
-
imageDownloader(_:willDownloadImageForURL:with:)
Default implementationCalled when the
ImageDownloader
object will start downloading an image from a specified URL.Default Implementation
Declaration
Swift
func imageDownloader(_ downloader: ImageDownloader, willDownloadImageForURL url: URL, with request: URLRequest?)
Parameters
downloader
The
ImageDownloader
object which is used for the downloading operation.url
URL of the starting request.
request
The request object for the download process.
-
imageDownloader(_:didFinishDownloadingImageForURL:with:error:)
Default implementationCalled when the
ImageDownloader
completes a downloading request with success or failure.Default Implementation
Declaration
Swift
func imageDownloader(_ downloader: ImageDownloader, didFinishDownloadingImageForURL url: URL, with response: URLResponse?, error: Error?)
Parameters
downloader
The
ImageDownloader
object which is used for the downloading operation.url
URL of the original request URL.
response
The response object of the downloading process.
error
The error in case of failure.
-
imageDownloader(_:didDownload:for:)
Default implementationCalled when the
ImageDownloader
object successfully downloaded image data from specified URL. This is your last chance to verify or modify the downloaded data before Kingfisher tries to perform addition processing on the image data.Note
This can be used to pre-process raw image data before creation ofImage
instance (i.e. decrypting or verification). Ifnil
returned, the processing is interrupted and aKingfisherError
withResponseErrorReason.dataModifyingFailed
will be raised. You could use this fact to stop the image processing flow if you find the data is corrupted or malformed.Default Implementation
Declaration
Swift
func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, for url: URL) -> Data?
Parameters
downloader
The
ImageDownloader
object which is used for the downloading operation.data
The original downloaded data.
url
The URL of the original request URL.
Return Value
The data from which Kingfisher should use to create an image. You need to provide valid data which content is one of the supported image file format. Kingfisher will perform process on this data and try to convert it to an image object.
-
imageDownloader(_:didDownload:for:with:)
Default implementationCalled when the
ImageDownloader
object successfully downloads and processes an image from specified URL.Default Implementation
Declaration
Swift
func imageDownloader(_ downloader: ImageDownloader, didDownload image: Image, for url: URL, with response: URLResponse?)
Parameters
downloader
The
ImageDownloader
object which is used for the downloading operation.image
The downloaded and processed image.
url
URL of the original request URL.
response
The original response object of the downloading process.
-
isValidStatusCode(_:for:)
Default implementationChecks if a received HTTP status code is valid or not. By default, a status code in range 200..<400 is considered as valid. If an invalid code is received, the downloader will raise an
KingfisherError
withResponseErrorReason.invalidHTTPStatusCode
as its reason.Note
If the default 200 to 400 valid code does not suit your need, you can implement this method to change that behavior.Default Implementation
Declaration
Swift
func isValidStatusCode(_ code: Int, for downloader: ImageDownloader) -> Bool
Parameters
code
The received HTTP status code.
downloader
The
ImageDownloader
object asks for validate status code.Return Value
Returns a value to indicate whether this HTTP status code is valid or not.