Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)secondAttempt {
- NSCache *memoryCache = [[NSCache alloc] init]; //assume there is a memoryCache for images or videos
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- NSString *urlString = @"http://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png";
- NSData *downloadedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
- if (downloadedData) {
- // STORE IN FILESYSTEM
- NSString* cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
- NSString *file = [cachesDirectory stringByAppendingPathComponent:urlString];
- [downloadedData writeToFile:file atomically:YES];
- // STORE IN MEMORY
- [memoryCache setObject:downloadedData forKey:@"downloadedPic"];
- }
- // NOW YOU CAN CREATE AN AVASSET OR UIIMAGE FROM THE FILE OR DATA
- NSURL *imageURL = [NSURL fileURLWithPath:@"downloadedPic"];
- NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
- UIImage *image = [UIImage imageWithData:imageData];
- [scheduleImage setImage:image];
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment