Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)dowloadPoject {
- AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
- manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
- BOOL __block responseFromCache = YES; // yes by default
- void (^requestSuccessBlock)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
- if (responseFromCache) {
- // response was returned from cache
- NSLog(@"RESPONSE FROM CACHE: %@", responseObject);
- }
- else {
- // response was returned from the server, not from cache
- NSLog(@"RESPONSE From Server: %@", responseObject);
- }
- UIImage *downloadedImage = [[UIImage alloc] init];
- downloadedImage = responseObject;
- // Add & Reload Data
- [self.projectImage addObject:downloadedImage];
- [self.projectname addObject:@"ABC"];
- [self reloadComingSoonProject];
- [self reloadNewReleaseProject];
- };
- void (^requestFailureBlock)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
- NSLog(@"ERROR: %@", error);
- };
- AFHTTPRequestOperation *operation = [manager GET:@"http://i359.photobucket.com/albums/oo34/SenaSLA/walls/Forward-Arrow-Button.png"
- parameters:nil
- success:requestSuccessBlock
- failure:requestFailureBlock];
- operation.responseSerializer = [AFImageResponseSerializer serializer];
- [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
- NSLog(@"bytesRead: %u, totalBytesRead: %lld, totalBytesExpectedToRead: %lld", bytesRead, totalBytesRead, totalBytesExpectedToRead);
- [self.viewNavBar.progressbar setProgress:(totalBytesRead/totalBytesExpectedToRead) animated:YES];
- }];
- [operation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
- // this will be called whenever server returns status code 200, not 304
- responseFromCache = NO;
- return cachedResponse;
- }];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement