redribben

images

Oct 26th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)secondAttempt {
  2.     NSCache *memoryCache; //assume there is a memoryCache for images or videos
  3.    
  4.     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  5.        
  6.         NSString *urlString = @"http://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png";
  7.        
  8.         NSData *downloadedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
  9.        
  10.         if (downloadedData) {
  11.            
  12.             // STORE IN FILESYSTEM
  13.             NSString* cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  14.             NSString *file = [cachesDirectory stringByAppendingPathComponent:urlString];
  15.             [downloadedData writeToFile:file atomically:YES];
  16.            
  17.             // STORE IN MEMORY
  18.             [memoryCache setObject:downloadedData forKey:@"downloadedPic"];
  19.         }
  20.        
  21.         // NOW YOU CAN CREATE AN AVASSET OR UIIMAGE FROM THE FILE OR DATA
  22.         NSData * imageData = [NSData dataWithContentsOfFile:@"downloadedPic"];
  23.         UIImage * image = [UIImage imageWithData:imageData];
  24.         [scheduleImage setImage:image];
  25.     });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment