Ensure we're not decoding the image in the main thread
This commit is contained in:
parent
570965f6cf
commit
ed690465d8
|
@ -50,6 +50,7 @@
|
||||||
if (self.isCancelled)
|
if (self.isCancelled)
|
||||||
{
|
{
|
||||||
self.finished = YES;
|
self.finished = YES;
|
||||||
|
[self reset];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,15 +95,27 @@
|
||||||
|
|
||||||
// As we cancelled the connection, its callback won't be called and thus won't
|
// As we cancelled the connection, its callback won't be called and thus won't
|
||||||
// maintain the isFinished and isExecuting flags.
|
// maintain the isFinished and isExecuting flags.
|
||||||
if (!self.isFinished) self.finished = YES;
|
|
||||||
if (self.isExecuting) self.executing = NO;
|
if (self.isExecuting) self.executing = NO;
|
||||||
|
if (!self.isFinished) self.finished = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self reset];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)done
|
- (void)done
|
||||||
{
|
{
|
||||||
self.finished = YES;
|
self.finished = YES;
|
||||||
self.executing = NO;
|
self.executing = NO;
|
||||||
|
[self reset];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)reset
|
||||||
|
{
|
||||||
|
self.cancelBlock = nil;
|
||||||
|
self.completedBlock = nil;
|
||||||
|
self.progressBlock = nil;
|
||||||
|
self.connection = nil;
|
||||||
|
self.imageData = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFinished:(BOOL)finished
|
- (void)setFinished:(BOOL)finished
|
||||||
|
@ -110,15 +123,6 @@
|
||||||
[self willChangeValueForKey:@"isFinished"];
|
[self willChangeValueForKey:@"isFinished"];
|
||||||
_finished = finished;
|
_finished = finished;
|
||||||
[self didChangeValueForKey:@"isFinished"];
|
[self didChangeValueForKey:@"isFinished"];
|
||||||
|
|
||||||
if (finished)
|
|
||||||
{
|
|
||||||
self.cancelBlock = nil;
|
|
||||||
self.completedBlock = nil;
|
|
||||||
self.progressBlock = nil;
|
|
||||||
self.connection = nil;
|
|
||||||
self.imageData = nil;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setExecuting:(BOOL)executing
|
- (void)setExecuting:(BOOL)executing
|
||||||
|
@ -234,8 +238,17 @@
|
||||||
|
|
||||||
if (self.completedBlock)
|
if (self.completedBlock)
|
||||||
{
|
{
|
||||||
UIImage *image = [UIImage decodedImageWithImage:SDScaledImageForPath(self.request.URL.absoluteString, self.imageData)];
|
__block SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
|
||||||
self.completedBlock(image, nil, YES);
|
UIImage *image = SDScaledImageForPath(self.request.URL.absoluteString, self.imageData);
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
|
||||||
|
{
|
||||||
|
UIImage *decodedImage = [UIImage decodedImageWithImage:image];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^
|
||||||
|
{
|
||||||
|
completionBlock(decodedImage, nil, YES);
|
||||||
|
completionBlock = nil;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[self done];
|
[self done];
|
||||||
|
|
Loading…
Reference in New Issue