ImageDownloader
open class ImageDownloader
Represents a downloading manager for requesting the image with a URL from server.
-
The default downloader.
Declaration
Swift
public static let `default`: ImageDownloader
-
The duration before the downloading is timeout. Default is 15 seconds.
Declaration
Swift
open var downloadTimeout: TimeInterval
-
A set of trusted hosts when receiving server trust challenges. A challenge with host name contained in this set will be ignored. You can use this set to specify the self-signed site. It only will be used if you don’t specify the
authenticationChallengeResponder
.If
authenticationChallengeResponder
is set, this property will be ignored and the implementation ofauthenticationChallengeResponder
will be used instead.Declaration
Swift
open var trustedHosts: Set<String>?
-
Use this to set supply a configuration for the downloader. By default, NSURLSessionConfiguration.ephemeralSessionConfiguration() will be used.
You could change the configuration before a downloading task starts. A configuration without persistent storage for caches is requested for downloader working correctly.
Declaration
Swift
open var sessionConfiguration: URLSessionConfiguration { get set }
-
Whether the download requests should use pipeline or not. Default is false.
Declaration
Swift
open var requestsUsePipelining: Bool
-
Delegate of this
ImageDownloader
object. SeeImageDownloaderDelegate
protocol for more.Declaration
Swift
open weak var delegate: ImageDownloaderDelegate?
-
A responder for authentication challenge. Downloader will forward the received authentication challenge for the downloading session to this responder.
Declaration
Swift
open weak var authenticationChallengeResponder: AuthenticationChallengeResponsable?
-
Creates a downloader with name.
Declaration
Swift
public init(name: String)
Parameters
name
The name for the downloader. It should not be empty.
-
Downloads an image with a URL and option.
Declaration
Swift
@discardableResult open func downloadImage( with url: URL, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
url
Target URL.
options
The options could control download behavior. See
KingfisherOptionsInfo
.progressBlock
Called when the download progress updated. This block will be always be called in main queue.
completionHandler
Called when the download progress finishes. This block will be called in the queue defined in
.callbackQueue
inoptions
parameter.Return Value
A downloading task. You could call
cancel
on it to stop the download task.
-
Undocumented
Declaration
Swift
@discardableResult open func downloadImage(with url: URL, retrieveImageTask: RetrieveImageTask? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: ImageDownloaderProgressBlock? = nil, completionHandler: ImageDownloaderCompletionHandler?) -> DownloadTask?
-
Cancel all downloading tasks for this
ImageDownloader
. It will trigger the completion handlers for all not-yet-finished downloading tasks.If you need to only cancel a certain task, call
cancel()
on theDownloadTask
returned by the downloading methods. If you need to cancel allDownloadTask
s of a certain url, useImageDownloader.cancel(url:)
.Declaration
Swift
public func cancelAll()
-
Cancel all downloading tasks for a given URL. It will trigger the completion handlers for all not-yet-finished downloading tasks for the URL.
Declaration
Swift
public func cancel(url: URL)
Parameters
url
The URL which you want to cancel downloading.