Ensure every data manipulation performed in NSURLConnection delegates are handled in the global background queue
This commit is contained in:
parent
bf1b946b9a
commit
b5bb74bf96
|
@ -161,6 +161,8 @@
|
|||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
|
||||
{
|
||||
[self.imageData appendData:data];
|
||||
|
||||
|
@ -227,30 +229,30 @@
|
|||
|
||||
CFRelease(imageSource);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection
|
||||
{
|
||||
self.connection = nil;
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
|
||||
|
||||
if (self.completedBlock)
|
||||
{
|
||||
__block SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
|
||||
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];
|
||||
UIImage *image = [UIImage decodedImageWithImage:SDScaledImageForPath(self.request.URL.absoluteString, self.imageData)];
|
||||
dispatch_async(dispatch_get_main_queue(), ^
|
||||
{
|
||||
completionBlock(decodedImage, nil, YES);
|
||||
completionBlock(image, nil, YES);
|
||||
completionBlock = nil;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[self done];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
|
||||
|
|
Loading…
Reference in New Issue