Created
May 28, 2012 14:31
-
-
Save jacksonfdam/2819465 to your computer and use it in GitHub Desktop.
Fetching Remote Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_queue_t img_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_async(img_queue, ^{ | |
NSURL *url = [NSURL URLWithString:@"http://imgs.xkcd.com/comics/formal_logic.png"]; | |
NSError *error = nil; | |
NSData *image = [NSData dataWithContentsOfURL:url options:0 error:&error]; | |
if(!error && image && [image length] > 0) { | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); | |
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"image.png"]; | |
[image writeToFile:path options:0 error:&error]; | |
} | |
UIImage *img = [UIImage imageWithData:image]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment