2011-10-17 09:28:15 -07:00
|
|
|
//
|
|
|
|
// Utilities.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 10/17/11.
|
|
|
|
// Copyright (c) 2011 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "Utilities.h"
|
|
|
|
|
|
|
|
@implementation Utilities
|
|
|
|
|
2011-10-17 09:28:40 -07:00
|
|
|
static NSCache *imageCache;
|
|
|
|
|
|
|
|
+ (void)saveImage:(UIImage *)image feedId:(NSString *)filename {
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *cacheDirectory = [paths objectAtIndex:0];
|
|
|
|
NSString *path = [cacheDirectory stringByAppendingPathComponent:filename];
|
|
|
|
|
|
|
|
[UIImageJPEGRepresentation(image, 1.0) writeToFile:path atomically:YES];
|
|
|
|
|
|
|
|
[imageCache setObject:image forKey:filename];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (UIImage *)getImage:(NSString *)filename {
|
|
|
|
UIImage *image;
|
|
|
|
|
|
|
|
image = [imageCache objectForKey:filename];
|
|
|
|
if (!image) {
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *cacheDirectory = [paths objectAtIndex:0];
|
|
|
|
NSString *path = [cacheDirectory stringByAppendingPathComponent:filename];
|
|
|
|
|
|
|
|
image = [UIImage imageWithContentsOfFile:path];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image) {
|
|
|
|
return image;
|
|
|
|
} else {
|
2011-10-17 09:37:16 -07:00
|
|
|
return [UIImage imageNamed:@"world.png"];
|
2011-10-17 09:28:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 09:28:15 -07:00
|
|
|
@end
|