diff --git a/SDImageCache.m b/SDImageCache.m index f9f57eb..40b43ef 100644 --- a/SDImageCache.m +++ b/SDImageCache.m @@ -41,8 +41,8 @@ static SDImageCache *instance; cacheInQueue.maxConcurrentOperationCount = 1; cacheOutQueue = [[NSOperationQueue alloc] init]; cacheOutQueue.maxConcurrentOperationCount = 1; -#if !TARGET_OS_IPHONE -#else + +#if TARGET_OS_IPHONE // Subscribe to app events [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearMemory) @@ -54,7 +54,7 @@ static SDImageCache *instance; name:UIApplicationWillTerminateNotification object:nil]; - #ifdef __IPHONE_4_0 +#ifdef __IPHONE_4_0 UIDevice *device = [UIDevice currentDevice]; if ([device respondsToSelector:@selector(isMultitaskingSupported)] && device.multitaskingSupported) { @@ -64,7 +64,7 @@ static SDImageCache *instance; name:UIApplicationDidEnterBackgroundNotification object:nil]; } - #endif +#endif #endif } @@ -126,12 +126,12 @@ static SDImageCache *instance; UIImage *image = [[self imageFromKey:key fromDisk:YES] retain]; // be thread safe with no lock if (image) { -#if !TARGET_OS_IPHONE +#if TARGET_OS_IPHONE + [fileManager createFileAtPath:[self cachePathForKey:key] contents:UIImageJPEGRepresentation(image, (CGFloat)1.0) attributes:nil]; +#else NSArray* representations = [image representations]; NSData* jpegData = [NSBitmapImageRep representationOfImageRepsInArray: representations usingType: NSJPEGFileType properties:nil]; [fileManager createFileAtPath:[self cachePathForKey:key] contents:jpegData attributes:nil]; -#else - [fileManager createFileAtPath:[self cachePathForKey:key] contents:UIImageJPEGRepresentation(image, (CGFloat)1.0) attributes:nil]; #endif [image release]; } diff --git a/SDWebImageDownloader.h b/SDWebImageDownloader.h index fe20bc0..4b4183c 100644 --- a/SDWebImageDownloader.h +++ b/SDWebImageDownloader.h @@ -20,7 +20,7 @@ extern NSString *const SDWebImageDownloadStopNotification; id delegate; NSURLConnection *connection; NSMutableData *imageData; - id userInfo; + id userInfo; BOOL lowPriority; } diff --git a/SDWebImageDownloader.m b/SDWebImageDownloader.m index 4762a96..f6740cf 100644 --- a/SDWebImageDownloader.m +++ b/SDWebImageDownloader.m @@ -22,13 +22,13 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot + (id)downloaderWithURL:(NSURL *)url delegate:(id)delegate { - return [[self class] downloaderWithURL:url delegate:delegate userInfo:nil]; + return [self downloaderWithURL:url delegate:delegate userInfo:nil]; } + (id)downloaderWithURL:(NSURL *)url delegate:(id)delegate userInfo:(id)userInfo { - return [[self class] downloaderWithURL:url delegate:delegate userInfo:userInfo lowPriority:NO]; + return [self downloaderWithURL:url delegate:delegate userInfo:userInfo lowPriority:NO]; } + (id)downloaderWithURL:(NSURL *)url delegate:(id)delegate userInfo:(id)userInfo lowPriority:(BOOL)lowPriority @@ -45,7 +45,7 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot selector:NSSelectorFromString(@"stopActivity") name:SDWebImageDownloadStopNotification object:nil]; } - + SDWebImageDownloader *downloader = [[[SDWebImageDownloader alloc] init] autorelease]; downloader.url = url; downloader.delegate = delegate; @@ -116,7 +116,7 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot { [delegate performSelector:@selector(imageDownloaderDidFinish:) withObject:self]; } - + if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)]) { UIImage *image = [[UIImage alloc] initWithData:imageData]; diff --git a/SDWebImageManager.m b/SDWebImageManager.m index 7384b32..46b5514 100644 --- a/SDWebImageManager.m +++ b/SDWebImageManager.m @@ -70,10 +70,10 @@ static SDWebImageManager *instance; { return; } - + // Check the on-disk cache async so we don't block the main thread NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:delegate, @"delegate", url, @"url", [NSNumber numberWithBool:lowPriority], @"low_priority", nil]; - [[SDImageCache sharedImageCache] queryDiskCacheForKey:[url absoluteString] delegate:self userInfo:info]; + [[SDImageCache sharedImageCache] queryDiskCacheForKey:[url absoluteString] delegate:self userInfo:info]; } - (void)cancelForDelegate:(id)delegate @@ -125,11 +125,13 @@ static SDWebImageManager *instance; downloader = [SDWebImageDownloader downloaderWithURL:url delegate:self userInfo:nil lowPriority:lowPriority]; [downloaderForURL setObject:downloader forKey:url]; } - + // If we get a normal priority request, make sure to change type since downloader is shared if (!lowPriority && downloader.lowPriority) + { downloader.lowPriority = NO; - + } + [delegates addObject:delegate]; [downloaders addObject:downloader]; }