Permalink
Browse files

Fix for missing avatar cache directory

  • Loading branch information...
1 parent cf724fe commit 6c10a054e81d364b787968ccbafc9755c958ea0e @dennisreimann committed Jun 21, 2013
Showing with 18 additions and 7 deletions.
  1. +2 −0 Classes/IOCAvatarCache.h
  2. +11 −4 Classes/IOCAvatarCache.m
  3. +3 −2 Classes/iOctocat.m
  4. +2 −1 iOctocatUnitTests/IOCAvatarCacheTests.m
View
2 Classes/IOCAvatarCache.h
@@ -3,4 +3,6 @@
+ (void)cacheGravatar:(UIImage *)image forIdentifier:(NSString *)string;
+ (NSString *)gravatarPathForIdentifier:(NSString *)string;
+ (void)clearAvatarCache;
++ (void)ensureAvatarCacheDirectory;
++ (void)removeAvatarCacheDirectory;
@end
View
15 Classes/IOCAvatarCache.m
@@ -10,11 +10,18 @@ + (NSString *)avatarsPath {
return avatarsPath;
}
+// removes old directory and entries, then creates new directory
+ (void)clearAvatarCache {
- NSFileManager *fileManager = [NSFileManager defaultManager];
- // remove old directory and entries, then create new directory
- [fileManager removeItemAtPath:self.avatarsPath error:nil];
- [fileManager createDirectoryAtPath:self.avatarsPath withIntermediateDirectories:NO attributes:nil error:nil];
+ [self removeAvatarCacheDirectory];
+ [self ensureAvatarCacheDirectory];
+}
+
++ (void)ensureAvatarCacheDirectory {
+ [[NSFileManager defaultManager] createDirectoryAtPath:self.avatarsPath withIntermediateDirectories:NO attributes:nil error:nil];
+}
+
++ (void)removeAvatarCacheDirectory {
+ [[NSFileManager defaultManager] removeItemAtPath:self.avatarsPath error:nil];
}
+ (NSString *)gravatarPathForIdentifier:(NSString *)string {
View
5 Classes/iOctocat.m
@@ -50,12 +50,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self deactivateURLCache];
[self setupHockeySDK];
[self setupAccounts];
+ [self setupAvatarCache];
[self setupSlidingViewController];
[self.window makeKeyAndVisible];
// remote notifications
NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification) [self application:application didReceiveRemoteNotification:remoteNotification];
- [self checkAvatarCache];
return YES;
}
@@ -266,12 +266,13 @@ - (void)setBadge:(NSInteger)number {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:number];
}
-- (void)checkAvatarCache {
+- (void)setupAvatarCache {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:ClearAvatarCacheDefaultsKey]) {
[IOCAvatarCache clearAvatarCache];
[defaults setValue:@NO forKey:ClearAvatarCacheDefaultsKey];
}
+ [IOCAvatarCache ensureAvatarCacheDirectory];
}
// NSURLCache seems to have a problem with Cache-Control="private" headers.
View
3 iOctocatUnitTests/IOCAvatarCacheTests.m
@@ -12,14 +12,15 @@ @implementation IOCAvatarCacheTests
- (void)setUp {
[super setUp];
+ [IOCAvatarCache ensureAvatarCacheDirectory];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
self.gravatar = [UIImage imageNamed:@"Icon.png"];
self.gravatarPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Avatars/gravatar.png"];
}
- (void)tearDown {
[super tearDown];
- [[NSFileManager defaultManager] removeItemAtPath:self.gravatarPath error:NULL];
+ [IOCAvatarCache removeAvatarCacheDirectory];
}
- (void)testGravatarPathForIdentifier {

0 comments on commit 6c10a05

Please sign in to comment.