Skip to content

Commit

Permalink
Made avatar file/fetch asynchronous to stop blocking the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Jman012 committed Mar 31, 2014
1 parent 177ba7e commit f6d1df6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Toxicity/Singleton/TXCSingleton.m
Expand Up @@ -171,7 +171,9 @@ - (void)avatarImageForKey:(NSString *)key type:(AvatarType)type finishBlock:(voi
finishBlock(tempImage);

} else {
[self loadAvatarForKey:key type:type finishBlock:finishBlock];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self loadAvatarForKey:key type:type finishBlock:finishBlock];
});
}

}
Expand All @@ -196,7 +198,9 @@ - (void)loadAvatarForKey:(NSString *)theKey type:(AvatarType)type finishBlock:(v
if (loadedAvatarImage) {
[self.avatarImageCache setObject:loadedAvatarImage forKey:theKey];
if (finishBlock) {
finishBlock(loadedAvatarImage);
dispatch_async(dispatch_get_main_queue(), ^{
finishBlock(loadedAvatarImage);
});
}

} else {
Expand Down Expand Up @@ -240,8 +244,11 @@ - (void)fetchRobohashAvatarForKey:(NSString *)theKey type:(AvatarType)type finis
NSString *theFilename = [[ourDocumentLocation stringByAppendingPathComponent:theKey] stringByAppendingPathExtension:@"png"];
[UIImagePNGRepresentation(downloadedImage) writeToFile:theFilename atomically:YES];

if (finishBlock)
finishBlock(downloadedImage);
if (finishBlock) {
dispatch_async(dispatch_get_main_queue(), ^{
finishBlock(downloadedImage);
});
}


} else {
Expand Down

0 comments on commit f6d1df6

Please sign in to comment.