Guest User

Untitled

a guest
Mar 9th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //      NSData *cachedData = [[ASIDownloadCache sharedCache] cachedResponseDataForURL:imageURL];
  2. //      UIImage *thumb;
  3. //      if(cachedData){
  4. //          thumb = [[UIImage imageWithData:cachedData] imageByScalingForSize:CGSizeMake(240.0f, 160.0f) withBackgroundColor:[UIColor whiteColor]];
  5. //          thumb = [thumb roundedCornerImage:NOVELL_CELL_RADIUS];
  6. //          self.mainImage = thumb;
  7. //          [self setNeedsDisplay];
  8. //            NSLog(@"image cached");
  9. //          return;
  10. //      }
  11.    
  12. //      __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:imageURL];
  13. //      [request setUsername:[DefaultsManager getUsername]];
  14. //      [request setPassword:[DefaultsManager getPassword]];
  15. //      [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
  16. //      [request setCompletionBlock:^{
  17. //          int statusCode = [request responseStatusCode];
  18. //          if(statusCode != 404){
  19. //              NSData *responseData = [request responseData];
  20. //              UIImage *thumb = [[UIImage imageWithData:responseData] imageByScalingForSize:CGSizeMake(240.0f, 160.0f) withBackgroundColor:[UIColor whiteColor]];
  21. //              thumb = [thumb roundedCornerImage:NOVELL_CELL_RADIUS];
  22. //              self.mainImage = thumb;
  23. //              [self setNeedsDisplay];
  24. //          }else{
  25. //              [[ASIDownloadCache sharedCache]removeCachedDataForRequest:request];
  26. //          }
  27. //      }];
  28.        
  29.         AFImageCache *image_cache = [[AFImageCache alloc] init];
  30.         NSData *cachedData;
  31.         [image_cache cacheImageData:cachedData forURL:imageURL cacheName:@"NovellInHand"];
  32.         UIImage *thumb;
  33.         if(cachedData){
  34.             thumb = [[UIImage imageWithData:cachedData] imageByScalingForSize:CGSizeMake(240.0f, 160.0f) withBackgroundColor:[UIColor whiteColor]];
  35.             thumb = [thumb roundedCornerImage:NOVELL_CELL_RADIUS];
  36.             self.mainImage = thumb;
  37.             [self setNeedsDisplay];
  38.             NSLog(@"image cached");
  39.             return;
  40.         }
  41.         [image_cache release];
  42.        
  43.         AFImageRequestOperation *image_request = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:imageURL]
  44.                                                                                       imageProcessingBlock:nil
  45.                                                                                                  cacheName:@"NovellInHand"
  46.                                                                                                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
  47.  
  48.                                                                                                        UIImage *thumb = [image imageByScalingForSize:CGSizeMake(240.0f, 160.0f) withBackgroundColor:[UIColor whiteColor]];
  49.                                                                                                        thumb = [thumb roundedCornerImage:NOVELL_CELL_RADIUS];
  50.                                                                                                        self.mainImage = thumb;
  51.                                                                                                        [self setNeedsDisplay];
  52.                                                                                                    }
  53.                                                                                                    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
  54.                                                                                                    
  55.                                                                                                    }];
Add Comment
Please, Sign In to add comment