2012-04-07 8 views
0

AFNetworkingクラスを使用して複数のファイルをダウンロードしようとしています。私はこれに完全に初心者です、私はAFHTTPClientの作業を把握しようとしています、私は操作でAFHTTPClientクラスのオブジェクトを初期化しましたが、私はちょうど操作での処理を開始する方法を見つけることができませんキュー。私もドキュメントを見てみましたが、何も見つかりませんでした。ここでAFHTTPClient複数ファイルのダウンロード

-(void)downloadFiles:(NSArray *)files { 
    if ([files count] > 0) { 
     NSMutableArray *operationArray = [[NSMutableArray alloc] init]; 
     for (int i = 0; i < [files count]; i++) { 
      ResourceFile *resourceFile = (ResourceFile*)[files objectAtIndex:i]; 

       NSString *urlString = [NSString stringWithFormat:@"%@views/ph_session?args=0", BASE_URL]; 
       NSURL *fileDownloadUrl = [[NSURL alloc] initWithString:urlString]; 
       NSMutableURLRequest *fileDownloadRequest = [[NSMutableURLRequest alloc] initWithURL:fileDownloadUrl]; 
       [fileDownloadRequest setValue:[SessionManager getSessionCookieForLogin] forHTTPHeaderField:@"Cookie"]; 
       void (^successBlock)(NSURLRequest *, NSHTTPURLResponse *, id) = ^(NSURLRequest *request, 
                        NSHTTPURLResponse *response, 
                        id JSON) { 
        NSLog(@"Success callback for file %@", resourceFile.filename); 
       }; 
       void (^failureBlock)(NSURLRequest*, NSHTTPURLResponse*, NSError*, id) = ^(NSURLRequest *request, 
                          NSHTTPURLResponse *response, 
                          NSError *err_, 
                          id JSON) { 
        NSLog(@"Failure callback for file %@", resourceFile.filename); 
       }; 
       AFJSONRequestOperation *operation = [AFJSONRequestOperation 
                JSONRequestOperationWithRequest:fileDownloadRequest 
                success:successBlock 
                failure:failureBlock]; 
       [operationArray addObject:operation]; 
     } 
     if ([operationArray count] > 0) { 
      AFHTTPClient *requestHandler = [[AFHTTPClient alloc] init]; 
      void (^progressBlock)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) = ^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) { 
       NSLog(@"%d proccesses completed out of %d", numberOfCompletedOperations, totalNumberOfOperations); 
      }; 
      void (^completionBlock)(NSArray *operations) = ^(NSArray *operations) { 
       NSLog(@"All operations completed"); 
      }; 

      [requestHandler enqueueBatchOfHTTPRequestOperations:operationArray 
                progressBlock:progressBlock 
               completionBlock:completionBlock]; 
     } 
    } else { 
     NSLog(@"No file to download"); 
    } 
} 

は、その配列、このメソッドに渡されるresourcefileもクラスである:

#import <Foundation/Foundation.h> 

@interface ResourceFile : NSObject { 
    NSInteger fid; 
    NSString *filemime; 
    NSString *filename; 
    NSString *filesize; 
    NSString *uri; 
    NSString *timestamp; 
} 

@property NSInteger fid; 
@property (retain, nonatomic) NSString *filemime; 
@property (retain, nonatomic) NSString *filename; 
@property (retain, nonatomic) NSString *filesize; 
@property (retain, nonatomic) NSString *uri; 
@property (retain, nonatomic) NSString *timestamp; 

-(id)initWithData:(id)data; 

@end 

誰も私は何を教えてくださいすることができここで

は、私が使用しているコードです。間違っている?

答えて

0

私は私がAFHTTPOperationsをキューになってるAFHTTPClient enqueueBatchOfHTTPRequestOperationsを、使用してAFJSONRequestOperationをエンキューしようとしていた、問題を発見した....

関連する問題