Ensure every data manipulation performed in NSURLConnection delegates are handled in the global background queue

This commit is contained in:
Olivier Poitrey 2012-11-06 10:03:59 +01:00
parent bf1b946b9a
commit b5bb74bf96
1 changed files with 64 additions and 62 deletions

View File

@ -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