Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. - (void)dowloadPoject {
  2.  
  3. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  4. manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
  5.  
  6. BOOL __block responseFromCache = YES; // yes by default
  7.  
  8. void (^requestSuccessBlock)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
  9. if (responseFromCache) {
  10. // response was returned from cache
  11. NSLog(@"RESPONSE FROM CACHE: %@", responseObject);
  12. }
  13. else {
  14. // response was returned from the server, not from cache
  15. NSLog(@"RESPONSE From Server: %@", responseObject);
  16. }
  17.  
  18. UIImage *downloadedImage = [[UIImage alloc] init];
  19. downloadedImage = responseObject;
  20.  
  21. // Add & Reload Data
  22. [self.projectImage addObject:downloadedImage];
  23. [self.projectname addObject:@"ABC"];
  24. [self reloadComingSoonProject];
  25. [self reloadNewReleaseProject];
  26. };
  27.  
  28. void (^requestFailureBlock)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
  29. NSLog(@"ERROR: %@", error);
  30. };
  31.  
  32. AFHTTPRequestOperation *operation = [manager GET:@"http://i359.photobucket.com/albums/oo34/SenaSLA/walls/Forward-Arrow-Button.png"
  33. parameters:nil
  34. success:requestSuccessBlock
  35. failure:requestFailureBlock];
  36. operation.responseSerializer = [AFImageResponseSerializer serializer];
  37.  
  38. [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
  39. NSLog(@"bytesRead: %u, totalBytesRead: %lld, totalBytesExpectedToRead: %lld", bytesRead, totalBytesRead, totalBytesExpectedToRead);
  40.  
  41. [self.viewNavBar.progressbar setProgress:(totalBytesRead/totalBytesExpectedToRead) animated:YES];
  42. }];
  43.  
  44. [operation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
  45. // this will be called whenever server returns status code 200, not 304
  46. responseFromCache = NO;
  47. return cachedResponse;
  48. }];
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement