From 8b315a35859a1abb0cc8ebd35d96a439dd030f5c Mon Sep 17 00:00:00 2001 From: jason Date: Sat, 15 Mar 2014 03:24:02 +0800 Subject: [PATCH] add support for high priority download --- SDWebImage/SDWebImageDownloader.h | 7 ++++++- SDWebImage/SDWebImageDownloader.m | 4 ++++ SDWebImage/SDWebImageManager.h | 8 +++++++- SDWebImage/SDWebImageManager.m | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index 25af27b..33ed776 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -37,7 +37,12 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { * Enable to allow untrusted SSL ceriticates. * Useful for testing purposes. Use with caution in production. */ - SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6 + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, + /** + * + */ + SDWebImageDownloaderHighPriority = 1 << 7, + }; diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 7e5247e..5b7cae2 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -152,6 +152,10 @@ static NSString *const kCompletedCallbackKey = @"completed"; SDWebImageDownloader *sself = wself; [sself removeCallbacksForURL:url]; }]; + + if (options & SDWebImageDownloaderHighPriority) { + operation.queuePriority = NSOperationQueuePriorityHigh; + } [wself.downloadQueue addOperation:operation]; if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index cce427d..1284ba7 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -55,7 +55,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { * Enable to allow untrusted SSL ceriticates. * Useful for testing purposes. Use with caution in production. */ - SDWebImageAllowInvalidSSLCertificates = 1 << 7 + SDWebImageAllowInvalidSSLCertificates = 1 << 7, + /** + * By default, image are loaded in the order they were queued. This flag move them to + * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which + * could take a while). + */ + SDWebImageHighPriority = 1 << 8 }; typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 312b3e7..2e893ec 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -127,6 +127,7 @@ if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground; if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies; if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates; + if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority; if (image && options & SDWebImageRefreshCached) { // force progressive off if image already cached but forced refreshing downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;