Merge branch 'master' of https://github.com/rs/SDWebImage
# Conflicts: # SDWebImage/SDWebImageCompat.m
This commit is contained in:
commit
886b857e8a
|
@ -145,7 +145,7 @@ There are three ways to use SDWebImage in your project:
|
|||
#### Podfile
|
||||
```
|
||||
platform :ios, '7.0'
|
||||
pod 'SDWebImage', '~>3.8'
|
||||
pod 'SDWebImage', '~> 4.0'
|
||||
```
|
||||
|
||||
If you are using Swift, be sure to add `use_frameworks!` and set your target to iOS 8+:
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||
|
@ -42,7 +42,7 @@
|
|||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder;
|
||||
placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||
|
@ -55,7 +55,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||
|
@ -86,7 +86,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
|
@ -37,7 +37,7 @@
|
|||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder;
|
||||
placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -51,7 +51,7 @@
|
|||
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
|
@ -83,7 +83,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
|
|
@ -351,8 +351,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
image = [UIImage decodedImageWithImage:image];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
// Apple's defines from TargetConditionals.h are a bit weird.
|
||||
// Seems like TARGET_OS_MAC is always defined (on all platforms).
|
||||
// To determine if we are running on OSX, we can only relly on TARGET_OS_IPHONE=0 and all the other platforms
|
||||
// To determine if we are running on OSX, we can only rely on TARGET_OS_IPHONE=0 and all the other platforms
|
||||
#if !TARGET_OS_IPHONE && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_WATCH
|
||||
#define SD_MAC 1
|
||||
#else
|
||||
|
|
|
@ -28,6 +28,7 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl
|
|||
for (UIImage *tempImage in image.images) {
|
||||
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
||||
}
|
||||
|
||||
UIImage *animatedImage = [UIImage animatedImageWithImages:scaledImages duration:image.duration];
|
||||
#ifdef SD_WEBP
|
||||
if (animatedImage) {
|
||||
|
@ -40,8 +41,7 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl
|
|||
}
|
||||
#endif
|
||||
return animatedImage;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
#if SD_WATCH
|
||||
if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)]) {
|
||||
#elif SD_UIKIT
|
||||
|
|
|
@ -119,6 +119,15 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
|
|||
@property (assign, nonatomic) NSTimeInterval downloadTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration in use by the internal NSURLSession.
|
||||
* Mutating this object directly has no effect.
|
||||
*
|
||||
* @see createNewSessionWithConfiguration:
|
||||
*/
|
||||
@property (readonly, nonatomic, nonnull) NSURLSessionConfiguration *sessionConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
|
||||
*/
|
||||
|
@ -230,4 +239,14 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
|
|||
*/
|
||||
- (void)cancelAllDownloads;
|
||||
|
||||
/**
|
||||
* Forces SDWebImageDownloader to create and use a new NSURLSession that is
|
||||
* initialized with the given configuration.
|
||||
* *Note*: All existing download operations in the queue will be cancelled.
|
||||
* *Note*: `timeoutIntervalForRequest` is going to be overwritten.
|
||||
*
|
||||
* @param sessionConfiguration The configuration to use for the new NSURLSession
|
||||
*/
|
||||
- (void)createNewSessionWithConfiguration:(nonnull NSURLSessionConfiguration *)sessionConfiguration;
|
||||
|
||||
@end
|
||||
|
|
|
@ -84,20 +84,30 @@
|
|||
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
|
||||
_downloadTimeout = 15.0;
|
||||
|
||||
sessionConfiguration.timeoutIntervalForRequest = _downloadTimeout;
|
||||
|
||||
/**
|
||||
* Create the session for this task
|
||||
* We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
|
||||
* method calls and completion handler calls.
|
||||
*/
|
||||
self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration
|
||||
delegate:self
|
||||
delegateQueue:nil];
|
||||
[self createNewSessionWithConfiguration:sessionConfiguration];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createNewSessionWithConfiguration:(NSURLSessionConfiguration *)sessionConfiguration {
|
||||
[self cancelAllDownloads];
|
||||
|
||||
if (self.session) {
|
||||
[self.session invalidateAndCancel];
|
||||
}
|
||||
|
||||
sessionConfiguration.timeoutIntervalForRequest = self.downloadTimeout;
|
||||
|
||||
/**
|
||||
* Create the session for this task
|
||||
* We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
|
||||
* method calls and completion handler calls.
|
||||
*/
|
||||
self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration
|
||||
delegate:self
|
||||
delegateQueue:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self.session invalidateAndCancel];
|
||||
self.session = nil;
|
||||
|
@ -109,8 +119,7 @@
|
|||
- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(nullable NSString *)field {
|
||||
if (value) {
|
||||
self.HTTPHeaders[field] = value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[self.HTTPHeaders removeObjectForKey:field];
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +140,10 @@
|
|||
return _downloadQueue.maxConcurrentOperationCount;
|
||||
}
|
||||
|
||||
- (NSURLSessionConfiguration *)sessionConfiguration {
|
||||
return self.session.configuration;
|
||||
}
|
||||
|
||||
- (void)setOperationClass:(nullable Class)operationClass {
|
||||
if (operationClass && [operationClass isSubclassOfClass:[NSOperation class]] && [operationClass conformsToProtocol:@protocol(SDWebImageDownloaderOperationInterface)]) {
|
||||
_operationClass = operationClass;
|
||||
|
@ -230,11 +243,13 @@
|
|||
|
||||
__weak SDWebImageDownloaderOperation *woperation = operation;
|
||||
operation.completionBlock = ^{
|
||||
SDWebImageDownloaderOperation *soperation = woperation;
|
||||
if (!soperation) return;
|
||||
if (self.URLOperations[url] == soperation) {
|
||||
[self.URLOperations removeObjectForKey:url];
|
||||
};
|
||||
dispatch_barrier_sync(self.barrierQueue, ^{
|
||||
SDWebImageDownloaderOperation *soperation = woperation;
|
||||
if (!soperation) return;
|
||||
if (self.URLOperations[url] == soperation) {
|
||||
[self.URLOperations removeObjectForKey:url];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
id downloadOperationCancelToken = [operation addHandlersForProgress:progressBlock completed:completedBlock];
|
||||
|
@ -248,7 +263,7 @@
|
|||
}
|
||||
|
||||
- (void)setSuspended:(BOOL)suspended {
|
||||
(self.downloadQueue).suspended = suspended;
|
||||
self.downloadQueue.suspended = suspended;
|
||||
}
|
||||
|
||||
- (void)cancelAllDownloads {
|
||||
|
|
|
@ -169,8 +169,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
|||
for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
|
||||
progressBlock(0, NSURLResponseUnknownLength, self.request.URL);
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:weakSelf];
|
||||
});
|
||||
} else {
|
||||
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}]];
|
||||
|
@ -201,8 +202,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
|||
|
||||
if (self.dataTask) {
|
||||
[self.dataTask cancel];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
||||
});
|
||||
|
||||
// As we cancelled the connection, its callback won't be called and thus won't
|
||||
|
@ -266,11 +268,11 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
|
||||
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
|
||||
self.response = response;
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:weakSelf];
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
NSUInteger code = ((NSHTTPURLResponse *)response).statusCode;
|
||||
|
||||
//This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
|
||||
|
@ -280,8 +282,9 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
} else {
|
||||
[self.dataTask cancel];
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
||||
});
|
||||
|
||||
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:((NSHTTPURLResponse *)response).statusCode userInfo:nil]];
|
||||
|
@ -402,10 +405,11 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||
@synchronized(self) {
|
||||
self.dataTask = nil;
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
||||
if (!error) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:weakSelf];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
|||
/**
|
||||
* Queue options for Prefetcher. Defaults to Main Queue.
|
||||
*/
|
||||
@property (nonatomic, assign, nonnull) dispatch_queue_t prefetcherQueue;
|
||||
@property (SDDispatchQueueSetterSementics, nonatomic, nonnull) dispatch_queue_t prefetcherQueue;
|
||||
|
||||
@property (weak, nonatomic, nullable) id <SDWebImagePrefetcherDelegate> delegate;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state;
|
||||
forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
|
@ -54,7 +54,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder;
|
||||
placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -69,7 +69,7 @@
|
|||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
|
@ -105,7 +105,7 @@
|
|||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -139,7 +139,7 @@
|
|||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
*/
|
||||
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state;
|
||||
forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
||||
|
@ -153,7 +153,7 @@
|
|||
*/
|
||||
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder;
|
||||
placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -168,7 +168,7 @@
|
|||
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`.
|
||||
|
@ -204,7 +204,7 @@
|
|||
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||
forState:(UIControlState)state
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url;
|
||||
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||
|
@ -35,7 +35,7 @@
|
|||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url`.
|
||||
|
@ -50,7 +50,7 @@
|
|||
* The fourth parameter is the original image url.
|
||||
*/
|
||||
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
|
@ -66,7 +66,7 @@
|
|||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder;
|
||||
placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -79,7 +79,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
options:(SDWebImageOptions)options;
|
||||
options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
|
@ -111,7 +111,7 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||
placeholderImage:(nullable UIImage *)placeholder
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
|
Loading…
Reference in New Issue