Added Mac OS X compatibility

This commit is contained in:
Jamie Pinkham 2011-03-15 09:05:49 -04:00 committed by Olivier Poitrey
parent ee153fee04
commit 3116810b18
7 changed files with 37 additions and 5 deletions

View File

@ -41,7 +41,8 @@ static SDImageCache *instance;
cacheInQueue.maxConcurrentOperationCount = 1;
cacheOutQueue = [[NSOperationQueue alloc] init];
cacheOutQueue.maxConcurrentOperationCount = 1;
#if !TARGET_OS_IPHONE
#else
// Subscribe to app events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearMemory)
@ -64,6 +65,7 @@ static SDImageCache *instance;
object:nil];
}
#endif
#endif
}
return self;
@ -98,7 +100,7 @@ static SDImageCache *instance;
{
const char *str = [key UTF8String];
unsigned char r[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), r);
CC_MD5(str, (CC_LONG)strlen(str), r);
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]];
@ -124,8 +126,14 @@ static SDImageCache *instance;
UIImage *image = [[self imageFromKey:key fromDisk:YES] retain]; // be thread safe with no lock
if (image)
{
#if !TARGET_OS_IPHONE
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];
[image release];
#endif
}
}

View File

@ -6,7 +6,7 @@
// Copyright 2010 Dailymotion. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SDWebImageCompat.h"
@class SDImageCache;

21
SDWebImageCompat.h Normal file
View File

@ -0,0 +1,21 @@
//
// SDWebImageCompat.h
// SDWebImageCompat
//
// Created by Jamie Pinkham on 3/15/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <TargetConditionals.h>
#if !TARGET_OS_IPHONE
#import <AppKit/AppKit.h>
#ifndef UIImage
#define UIImage NSImage
#endif
#ifndef UIImageView
#define UIImageView NSImageView
#endif
#else
#import <UIKit/UIKit.h>
#endif

View File

@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import "SDWebImageDownloaderDelegate.h"
#import "SDWebImageCompat.h"
extern NSString *const SDWebImageDownloadStartNotification;
extern NSString *const SDWebImageDownloadStopNotification;

View File

@ -6,6 +6,8 @@
* file that was distributed with this source code.
*/
#import "SDWebImageCompat.h"
@class SDWebImageDownloader;
@protocol SDWebImageDownloaderDelegate <NSObject>

View File

@ -6,7 +6,7 @@
* file that was distributed with this source code.
*/
#import <UIKit/UIKit.h>
#import "SDWebImageCompat.h"
#import "SDWebImageDownloaderDelegate.h"
#import "SDWebImageManagerDelegate.h"
#import "SDImageCacheDelegate.h"

View File

@ -6,7 +6,7 @@
* file that was distributed with this source code.
*/
#import <UIKit/UIKit.h>
#import "SDWebImageCompat.h"
#import "SDWebImageManagerDelegate.h"
@interface UIImageView (WebCache) <SDWebImageManagerDelegate>