/* * This file is part of the SDWebImage package. * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ #import #import "EMSDWebImageCompat.h" #import "EMSDWebImageOperation.h" typedef NS_OPTIONS(NSUInteger, EMSDWebImageDownloaderOptions) { EMSDWebImageDownloaderLowPriority = 1 << 0, EMSDWebImageDownloaderProgressiveDownload = 1 << 1, /** * By default, request prevent the of NSURLCache. With this flag, NSURLCache * is used with default policies. */ EMSDWebImageDownloaderUseNSURLCache = 1 << 2, /** * Call completion block with nil image/imageData if the image was read from NSURLCache * (to be combined with `EMSDWebImageDownloaderUseNSURLCache`). */ EMSDWebImageDownloaderIgnoreCachedResponse = 1 << 3, /** * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for * extra time in background to let the request finish. If the background task expires the operation will be cancelled. */ EMSDWebImageDownloaderContinueInBackground = 1 << 4, /** * Handles cookies stored in NSHTTPCookieStore by setting * NSMutableURLRequest.HTTPShouldHandleCookies = YES; */ EMSDWebImageDownloaderHandleCookies = 1 << 5, /** * Enable to allow untrusted SSL ceriticates. * Useful for testing purposes. Use with caution in production. */ EMSDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, /** * Put the image in the high priority queue. */ EMSDWebImageDownloaderHighPriority = 1 << 7, }; typedef NS_ENUM(NSInteger, EMSDWebImageDownloaderExecutionOrder) { /** * Default value. All download operations will execute in queue style (first-in-first-out). */ EMSDWebImageDownloaderFIFOExecutionOrder, /** * All download operations will execute in stack style (last-in-first-out). */ EMSDWebImageDownloaderLIFOExecutionOrder }; extern NSString *const EMSDWebImageDownloadStartNotification; extern NSString *const EMSDWebImageDownloadStopNotification; typedef void(^EMSDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); typedef void(^EMSDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); typedef NSDictionary *(^EMSDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); /** * Asynchronous downloader dedicated and optimized for image loading. */ @interface EMSDWebImageDownloader : NSObject @property (assign, nonatomic) NSInteger maxConcurrentDownloads; /** * Shows the current amount of downloads that still need to be downloaded */ @property (readonly, nonatomic) NSUInteger currentDownloadCount; /** * The timeout value (in seconds) for the download operation. Default: 15.0. */ @property (assign, nonatomic) NSTimeInterval downloadTimeout; /** * Changes download operations execution order. Default value is `EMSDWebImageDownloaderFIFOExecutionOrder`. */ @property (assign, nonatomic) EMSDWebImageDownloaderExecutionOrder executionOrder; /** * Singleton method, returns the shared instance * * @return global shared instance of downloader class */ + (EMSDWebImageDownloader *)sharedDownloader; /** * Set username */ @property (strong, nonatomic) NSString *username; /** * Set password */ @property (strong, nonatomic) NSString *password; /** * Set filter to pick headers for downloading image HTTP request. * * This block will be invoked for each downloading image request, returned * NSDictionary will be used as headers in corresponding HTTP request. */ @property (nonatomic, copy) EMSDWebImageDownloaderHeadersFilterBlock headersFilter; /** * Set a value for a HTTP header to be appended to each download HTTP request. * * @param value The value for the header field. Use `nil` value to remove the header. * @param field The name of the header field to set. */ - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; /** * Returns the value of the specified HTTP header field. * * @return The value associated with the header field field, or `nil` if there is no corresponding header field. */ - (NSString *)valueForHTTPHeaderField:(NSString *)field; /** * Creates a EMSDWebImageDownloader async downloader instance with a given URL * * The delegate will be informed when the image is finish downloaded or an error has happen. * * @see EMSDWebImageDownloaderDelegate * * @param url The URL to the image to download * @param options The options to be used for this download * @param progressBlock A block called repeatedly while the image is downloading * @param completedBlock A block called once the download is completed. * If the download succeeded, the image parameter is set, in case of error, * error parameter is set with the error. The last parameter is always YES * if EMSDWebImageDownloaderProgressiveDownload isn't use. With the * EMSDWebImageDownloaderProgressiveDownload option, this block is called * repeatedly with the partial image object and the finished argument set to NO * before to be called a last time with the full image and finished argument * set to YES. In case of error, the finished argument is always YES. * * @return A cancellable EMSDWebImageOperation */ - (id )downloadImageWithURL:(NSURL *)url options:(EMSDWebImageDownloaderOptions)options progress:(EMSDWebImageDownloaderProgressBlock)progressBlock completed:(EMSDWebImageDownloaderCompletedBlock)completedBlock; /** * Sets the download queue suspension state */ - (void)setSuspended:(BOOL)suspended; @end