mirror of
https://github.com/zhigang1992/PINRemoteImage.git
synced 2026-03-28 08:08:45 +08:00
Merge branch 'maicki-feature/add-download-progress'
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
NSMutableArray *progress = [[NSMutableArray alloc] init];
|
||||
[[PINRemoteImageManager sharedImageManager]
|
||||
downloadImageWithURL:progressiveURL
|
||||
options:PINRemoteImageManagerDownloadOptionsNone progress:^(PINRemoteImageManagerResult *result) {
|
||||
options:PINRemoteImageManagerDownloadOptionsNone progressImage:^(PINRemoteImageManagerResult *result) {
|
||||
[progress addObject:result.image];
|
||||
} completion:^(PINRemoteImageManagerResult *result) {
|
||||
[progress addObject:result.image];
|
||||
|
||||
@@ -683,7 +683,7 @@
|
||||
__block UIImage *image;
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Medium], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
@@ -699,7 +699,7 @@
|
||||
[self.imageManager setCurrentBytesPerSecond:5];
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Medium], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
@@ -711,7 +711,7 @@
|
||||
[self.imageManager.cache removeAllObjects];
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Medium], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
@@ -725,7 +725,7 @@
|
||||
[self.imageManager setCurrentBytesPerSecond:100];
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Medium], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
@@ -742,7 +742,7 @@
|
||||
[self.imageManager setCurrentBytesPerSecond:7];
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Medium], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
@@ -770,7 +770,7 @@
|
||||
[self.imageManager setCurrentBytesPerSecond:7];
|
||||
[self.imageManager downloadImageWithURLs:@[[self JPEGURL_Small], [self JPEGURL_Large]]
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
image = result.image;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
NSMutableArray *progress = [[NSMutableArray alloc] init];
|
||||
[[PINRemoteImageManager sharedImageManager]
|
||||
downloadImageWithURL:progressiveURL
|
||||
options:PINRemoteImageManagerDownloadOptionsNone progress:^(PINRemoteImageManagerResult *result) {
|
||||
options:PINRemoteImageManagerDownloadOptionsNone progressImage:^(PINRemoteImageManagerResult *result) {
|
||||
[progress addObject:result.image];
|
||||
} completion:^(PINRemoteImageManagerResult *result) {
|
||||
[progress addObject:result.image];
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
@interface PINRemoteImageCallbacks : NSObject
|
||||
|
||||
@property (nonatomic, strong, nullable) PINRemoteImageManagerImageCompletion completionBlock;
|
||||
@property (nonatomic, strong, nullable) PINRemoteImageManagerImageCompletion progressBlock;
|
||||
@property (nonatomic, strong, nullable) PINRemoteImageManagerImageCompletion progressImageBlock;
|
||||
@property (nonatomic, strong, nullable) PINRemoteImageManagerProgressDownload progressDownloadBlock;
|
||||
@property (nonatomic, assign) CFTimeInterval requestTime;
|
||||
|
||||
@end
|
||||
|
||||
@@ -259,7 +259,7 @@
|
||||
if (urls.count > 1) {
|
||||
downloadImageOperationUUID = [[PINRemoteImageManager sharedImageManager] downloadImageWithURLs:urls
|
||||
options:options
|
||||
progress:internalProgress
|
||||
progressImage:internalProgress
|
||||
completion:internalCompletion];
|
||||
} else if (processorKey.length > 0 && processor) {
|
||||
downloadImageOperationUUID = [[PINRemoteImageManager sharedImageManager] downloadImageWithURL:urls[0]
|
||||
@@ -270,7 +270,7 @@
|
||||
} else {
|
||||
downloadImageOperationUUID = [[PINRemoteImageManager sharedImageManager] downloadImageWithURL:urls[0]
|
||||
options:options
|
||||
progress:internalProgress
|
||||
progressImage:internalProgress
|
||||
completion:internalCompletion];
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
{
|
||||
__block BOOL hasProgressBlocks = NO;
|
||||
[self.callbackBlocks enumerateKeysAndObjectsUsingBlock:^(NSUUID *UUID, PINRemoteImageCallbacks *callback, BOOL *stop) {
|
||||
if (callback.progressBlock) {
|
||||
if (callback.progressImageBlock) {
|
||||
hasProgressBlocks = YES;
|
||||
*stop = YES;
|
||||
}
|
||||
@@ -42,15 +42,16 @@
|
||||
- (void)callProgressWithQueue:(dispatch_queue_t)queue withImage:(PINImage *)image
|
||||
{
|
||||
[self.callbackBlocks enumerateKeysAndObjectsUsingBlock:^(NSUUID *UUID, PINRemoteImageCallbacks *callback, BOOL *stop) {
|
||||
if (callback.progressBlock != nil) {
|
||||
if (callback.progressImageBlock != nil) {
|
||||
PINLog(@"calling progress for UUID: %@ key: %@", UUID, self.key);
|
||||
dispatch_async(queue, ^
|
||||
{
|
||||
callback.progressBlock([PINRemoteImageManagerResult imageResultWithImage:image
|
||||
animatedImage:nil
|
||||
requestLength:CACurrentMediaTime() - callback.requestTime
|
||||
error:nil
|
||||
resultType:PINRemoteImageResultTypeProgress UUID:UUID]);
|
||||
callback.progressImageBlock([PINRemoteImageManagerResult imageResultWithImage:image
|
||||
animatedImage:nil
|
||||
requestLength:CACurrentMediaTime() - callback.requestTime
|
||||
error:nil
|
||||
resultType:PINRemoteImageResultTypeProgress
|
||||
UUID:UUID]);
|
||||
});
|
||||
}
|
||||
}];
|
||||
|
||||
@@ -114,6 +114,14 @@ typedef void(^PINRemoteImageManagerAuthenticationChallengeCompletionHandler)(NSU
|
||||
*/
|
||||
typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * __nullable task, NSURLAuthenticationChallenge * __nonnull challenge, PINRemoteImageManagerAuthenticationChallengeCompletionHandler __nullable aHandler);
|
||||
|
||||
/**
|
||||
Handler called for many PINRemoteImage tasks providing the progress of the download.
|
||||
|
||||
@param completedBytes Amount of bytes that have been downloaded so far.
|
||||
@param totalBytes Total amount of bytes in the image being downloaded.
|
||||
*/
|
||||
typedef void(^PINRemoteImageManagerProgressDownload)(NSInteger completedBytes, NSInteger totalBytes);
|
||||
|
||||
@interface PINRemoteImageManager : NSObject
|
||||
|
||||
@property (nonatomic, readonly, nonnull) PINCache * cache;
|
||||
@@ -155,7 +163,7 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
|
||||
/**
|
||||
Set the minimum BPS to download the highest quality image in a set.
|
||||
@see downloadImageWithURLs:options:progress:completion:
|
||||
@see downloadImageWithURLs:options:progressImage:completion:
|
||||
|
||||
@param highQualityBPSThreshold bytes per second minimum. Defaults to 500000.
|
||||
@param completion Completion to be called once highQualityBPSThreshold has been set.
|
||||
@@ -164,7 +172,7 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
|
||||
/**
|
||||
Set the maximum BPS to download the lowest quality image in a set.
|
||||
@see downloadImageWithURLs:options:progress:completion:
|
||||
@see downloadImageWithURLs:options:progressImage:completion:
|
||||
|
||||
@param lowQualityBPSThreshold bytes per second maximum. Defaults to 50000.
|
||||
@param completion Completion to be called once lowQualityBPSThreshold has been set.
|
||||
@@ -174,7 +182,7 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
|
||||
/**
|
||||
Set whether high quality images should be downloaded when a low quality image is cached if network connectivity has improved.
|
||||
@see downloadImageWithURLs:options:progress:completion:
|
||||
@see downloadImageWithURLs:options:progressImage:completion:
|
||||
|
||||
@param shouldUpgradeLowQualityImages if YES, low quality images will be 'upgraded'.
|
||||
@param completion Completion to be called once shouldUpgradeLowQualityImages has been set.
|
||||
@@ -292,14 +300,46 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
|
||||
@param url NSURL where the image to download resides.
|
||||
@param options PINRemoteImageManagerDownloadOptions options with which to fetch the image.
|
||||
@param progress PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.
|
||||
@param progressImage PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.
|
||||
@param completion PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.
|
||||
|
||||
@return An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).
|
||||
*/
|
||||
- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progress:(nullable PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).
|
||||
|
||||
@param url NSURL where the image to download resides.
|
||||
@param options PINRemoteImageManagerDownloadOptions options with which to fetch the image.
|
||||
@param progressDownload PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.
|
||||
@param completion PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.
|
||||
|
||||
@return An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).
|
||||
*/
|
||||
- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).
|
||||
|
||||
@param url NSURL where the image to download resides.
|
||||
@param options PINRemoteImageManagerDownloadOptions options with which to fetch the image.
|
||||
@param progressImage PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.
|
||||
@param progressDownload PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.
|
||||
@param completion PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.
|
||||
|
||||
@return An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).
|
||||
*/
|
||||
- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage
|
||||
progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
@@ -319,6 +359,25 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
processor:(nullable PINRemoteImageManagerImageProcessor)processor
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
Download or retrieve from cache the image found at the url and process it before calling completion. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).
|
||||
|
||||
@param url NSURL where the image to download resides.
|
||||
@param options PINRemoteImageManagerDownloadOptions options with which to fetch the image.
|
||||
@param processorKey NSString key to uniquely identify processor and process. Will be used for caching processed images.
|
||||
@param progressDownload PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.
|
||||
@param processor PINRemoteImageManagerImageProcessor block which will be called to post-process downloaded image.
|
||||
@param completion PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.
|
||||
|
||||
@return An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).
|
||||
*/
|
||||
- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
processorKey:(nullable NSString *)processorKey
|
||||
processor:(nullable PINRemoteImageManagerImageProcessor)processor
|
||||
progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
Download or retrieve from cache one of the images found at the urls in the passed in array based on current network performance. URLs should be sorted from lowest quality image URL to highest. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).
|
||||
|
||||
@@ -326,14 +385,14 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
|
||||
@param urls An array of NSURLs of increasing size.
|
||||
@param options PINRemoteImageManagerDownloadOptions options with which to fetch the image.
|
||||
@param progress PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.
|
||||
@param progressImage PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.
|
||||
@param completion PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.
|
||||
|
||||
@return An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).
|
||||
*/
|
||||
- (nullable NSUUID *)downloadImageWithURLs:(nonnull NSArray <NSURL *> *)urls
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progress:(nullable PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage
|
||||
completion:(nullable PINRemoteImageManagerImageCompletion)completion;
|
||||
|
||||
/**
|
||||
@@ -375,9 +434,9 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
/**
|
||||
* @abstract set the progress callback on a download task. You can use this to add progress callbacks or remove them for in flight downloads
|
||||
*
|
||||
* @param progressCallback a PINRemoteImageManagerImageCompletion block to be called with a progress update
|
||||
* @param progressImageCallback a PINRemoteImageManagerImageCompletion block to be called with a progress update
|
||||
* @param UUID NSUUID of the task to set the priority on.
|
||||
*/
|
||||
- (void)setProgressCallback:(nullable PINRemoteImageManagerImageCompletion)progress ofTaskWithUUID:(nonnull NSUUID *)UUID;
|
||||
- (void)setProgressImageCallback:(nullable PINRemoteImageManagerImageCompletion)progressImageBlock ofTaskWithUUID:(nonnull NSUUID *)UUID;
|
||||
|
||||
@end
|
||||
|
||||
@@ -367,13 +367,13 @@ static dispatch_once_t sharedDispatchToken;
|
||||
{
|
||||
return [self downloadImageWithURL:url
|
||||
options:options
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (NSUUID *)downloadImageWithURL:(NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progress:(PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
{
|
||||
return [self downloadImageWithURL:url
|
||||
@@ -381,7 +381,41 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progress:progress
|
||||
progressImage:progressImage
|
||||
progressDownload:nil
|
||||
completion:completion
|
||||
inputUUID:nil];
|
||||
}
|
||||
|
||||
- (NSUUID *)downloadImageWithURL:(NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progressDownload:(PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
{
|
||||
return [self downloadImageWithURL:url
|
||||
options:options
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progressImage:nil
|
||||
progressDownload:progressDownload
|
||||
completion:completion
|
||||
inputUUID:nil];
|
||||
}
|
||||
|
||||
- (NSUUID *)downloadImageWithURL:(NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
progressDownload:(PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
{
|
||||
return [self downloadImageWithURL:url
|
||||
options:options
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progressImage:progressImage
|
||||
progressDownload:progressDownload
|
||||
completion:completion
|
||||
inputUUID:nil];
|
||||
}
|
||||
@@ -397,17 +431,37 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:processorKey
|
||||
processor:processor
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
progressDownload:nil
|
||||
completion:completion
|
||||
inputUUID:nil];
|
||||
}
|
||||
|
||||
- (NSUUID *)downloadImageWithURL:(NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
processorKey:(NSString *)processorKey
|
||||
processor:(PINRemoteImageManagerImageProcessor)processor
|
||||
progressDownload:(PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
{
|
||||
return [self downloadImageWithURL:url
|
||||
options:options
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:processorKey
|
||||
processor:processor
|
||||
progressImage:nil
|
||||
progressDownload:progressDownload
|
||||
completion:completion
|
||||
inputUUID:nil];
|
||||
}
|
||||
|
||||
- (NSUUID *)downloadImageWithURL:(NSURL *)url
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
priority:(PINRemoteImageManagerPriority)priority
|
||||
processorKey:(NSString *)processorKey
|
||||
processor:(PINRemoteImageManagerImageProcessor)processor
|
||||
progress:(PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
progressDownload:(PINRemoteImageManagerProgressDownload)progressDownload
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
inputUUID:(NSUUID *)UUID
|
||||
{
|
||||
@@ -468,7 +522,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
taskExisted = YES;
|
||||
PINLog(@"Task exists, attaching with key: %@, URL: %@, UUID: %@, task: %@", key, url, UUID, task);
|
||||
}
|
||||
[task addCallbacksWithCompletionBlock:completion progressBlock:progress withUUID:UUID];
|
||||
[task addCallbacksWithCompletionBlock:completion progressImageBlock:progressImage progressDownloadBlock:progressDownload withUUID:UUID];
|
||||
[strongSelf.tasks setObject:task forKey:key];
|
||||
|
||||
BlockAssert(taskClass == [task class], @"Task class should be the same!");
|
||||
@@ -520,7 +574,8 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:priority
|
||||
processorKey:processorKey
|
||||
processor:processor
|
||||
progress:(PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
progressDownload:nil
|
||||
completion:completion
|
||||
inputUUID:UUID];
|
||||
}
|
||||
@@ -539,7 +594,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
options:options
|
||||
priority:priority
|
||||
key:key
|
||||
progress:progress
|
||||
progressImage:progressImage
|
||||
UUID:UUID];
|
||||
}
|
||||
}
|
||||
@@ -653,7 +708,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
priority:(PINRemoteImageManagerPriority)priority
|
||||
key:(NSString *)key
|
||||
progress:(PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
UUID:(NSUUID *)UUID
|
||||
{
|
||||
[self lock];
|
||||
@@ -941,7 +996,8 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:PINRemoteImageManagerPriorityVeryLow
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progress:nil
|
||||
progressImage:nil
|
||||
progressDownload:nil
|
||||
completion:nil
|
||||
inputUUID:nil];
|
||||
}
|
||||
@@ -1008,7 +1064,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setProgressCallback:(nullable PINRemoteImageManagerImageCompletion)progress ofTaskWithUUID:(nonnull NSUUID *)UUID
|
||||
- (void)setProgressImageCallback:(nullable PINRemoteImageManagerImageCompletion)progressImageBlock ofTaskWithUUID:(nonnull NSUUID *)UUID
|
||||
{
|
||||
if (UUID == nil) {
|
||||
return;
|
||||
@@ -1025,7 +1081,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
if ([blockUUID isEqual:UUID]) {
|
||||
if ([task isKindOfClass:[PINRemoteImageDownloadTask class]]) {
|
||||
PINRemoteImageCallbacks *callbacks = task.callbackBlocks[blockUUID];
|
||||
callbacks.progressBlock = progress;
|
||||
callbacks.progressImageBlock = progressImageBlock;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1121,12 +1177,26 @@ static dispatch_once_t sharedDispatchToken;
|
||||
task.progressImage.progressThresholds = self.progressThresholds;
|
||||
}
|
||||
}
|
||||
|
||||
// Store callback blocks and call them after, that way blocking the callback won't lock up PINRemoteImageManager
|
||||
NSArray *callbackBlocks = task.callbackBlocks.allValues;
|
||||
|
||||
PINProgressiveImage *progressiveImage = task.progressImage;
|
||||
BOOL hasProgressBlocks = task.hasProgressBlocks;
|
||||
BOOL shouldBlur = self.shouldBlurProgressive;
|
||||
CGSize maxProgressiveRenderSize = self.maxProgressiveRenderSize;
|
||||
[self unlock];
|
||||
|
||||
for (PINRemoteImageCallbacks *imageCallback in callbackBlocks) {
|
||||
PINRemoteImageManagerProgressDownload progressDownloadBlock = imageCallback.progressDownloadBlock;
|
||||
if (progressDownloadBlock) {
|
||||
// For performance reasons we don't call on main thread (leave it up to the user)
|
||||
dispatch_async(self.callbackQueue, ^{
|
||||
progressDownloadBlock(dataTask.countOfBytesReceived, dataTask.countOfBytesExpectedToReceive);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[progressiveImage updateProgressiveImageWithData:data expectedNumberOfBytes:[dataTask countOfBytesExpectedToReceive]];
|
||||
|
||||
if (hasProgressBlocks && [NSOperation instancesRespondToSelector:@selector(qualityOfService)]) {
|
||||
@@ -1232,7 +1302,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
|
||||
- (NSUUID *)downloadImageWithURLs:(NSArray <NSURL *> *)urls
|
||||
options:(PINRemoteImageManagerDownloadOptions)options
|
||||
progress:(PINRemoteImageManagerImageCompletion)progress
|
||||
progressImage:(PINRemoteImageManagerImageCompletion)progressImage
|
||||
completion:(PINRemoteImageManagerImageCompletion)completion
|
||||
{
|
||||
NSUUID *UUID = [NSUUID UUID];
|
||||
@@ -1243,7 +1313,8 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progress:progress
|
||||
progressImage:progressImage
|
||||
progressDownload:nil
|
||||
completion:completion
|
||||
inputUUID:UUID];
|
||||
return UUID;
|
||||
@@ -1313,7 +1384,8 @@ static dispatch_once_t sharedDispatchToken;
|
||||
priority:PINRemoteImageManagerPriorityMedium
|
||||
processorKey:nil
|
||||
processor:nil
|
||||
progress:progress
|
||||
progressImage:progressImage
|
||||
progressDownload:nil
|
||||
completion:^(PINRemoteImageManagerResult *result) {
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
//clean out any lower quality images from the cache
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
@property (nonatomic, copy, nullable) NSString *key;
|
||||
#endif
|
||||
|
||||
- (void)addCallbacksWithCompletionBlock:(nonnull PINRemoteImageManagerImageCompletion)completionBlock progressBlock:(nullable PINRemoteImageManagerImageCompletion)progressBlock withUUID:(nonnull NSUUID *)UUID;
|
||||
- (void)addCallbacksWithCompletionBlock:(nonnull PINRemoteImageManagerImageCompletion)completionBlock
|
||||
progressImageBlock:(nullable PINRemoteImageManagerImageCompletion)progressImageBlock
|
||||
progressDownloadBlock:(nullable PINRemoteImageManagerProgressDownload)progressDownloadBlock
|
||||
withUUID:(nonnull NSUUID *)UUID;
|
||||
- (void)removeCallbackWithUUID:(nonnull NSUUID *)UUID;
|
||||
- (void)callCompletionsWithQueue:(nonnull dispatch_queue_t)queue remove:(BOOL)remove withImage:(nullable PINImage *)image animatedImage:(nullable FLAnimatedImage *)animatedImage cached:(BOOL)cached error:(nullable NSError *)error;
|
||||
//returns YES if no more attached completionBlocks
|
||||
|
||||
@@ -25,11 +25,15 @@
|
||||
return [NSString stringWithFormat:@"<%@: %p> completionBlocks: %lu", NSStringFromClass([self class]), self, (unsigned long)self.callbackBlocks.count];
|
||||
}
|
||||
|
||||
- (void)addCallbacksWithCompletionBlock:(PINRemoteImageManagerImageCompletion)completionBlock progressBlock:(PINRemoteImageManagerImageCompletion)progressBlock withUUID:(NSUUID *)UUID
|
||||
- (void)addCallbacksWithCompletionBlock:(PINRemoteImageManagerImageCompletion)completionBlock
|
||||
progressImageBlock:(PINRemoteImageManagerImageCompletion)progressImageBlock
|
||||
progressDownloadBlock:(PINRemoteImageManagerProgressDownload)progressDownloadBlock
|
||||
withUUID:(NSUUID *)UUID
|
||||
{
|
||||
PINRemoteImageCallbacks *completion = [[PINRemoteImageCallbacks alloc] init];
|
||||
completion.completionBlock = completionBlock;
|
||||
completion.progressBlock = progressBlock;
|
||||
completion.progressImageBlock = progressImageBlock;
|
||||
completion.progressDownloadBlock = progressDownloadBlock;
|
||||
|
||||
[self.callbackBlocks setObject:completion forKey:UUID];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user