2012-07-04 4 views
0

구매가 완료되면 서버에서 이미지, 오디오 및 비디오를 제거하고 싶습니다.ASIHttprequest 하나의 progressview로 다중 요청 요청

현재 이미지를 다운로드 할 수 있고 UIProgressView에서 진행 상황을 볼 수 있지만 여러 URL 요청에 대해 어떻게 단일 UIProgressView를 표시 할 수 있는지 잘 모르겠습니다.

ASIHttpRequest를 사용하여 여러 URL 요청에 대해 하나의 UIProgressView를 표시 할 수 있는지 여부를 알고 싶습니다.

진행 방법을 알려주십시오. 감사합니다.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     self.request=nil; 
    } 
    return self; 
} 

- (void)fetchThreeImages1:(id)sender 
{ 
    [imageView1 setImage:nil]; 

    if (!networkQueue) { 
     networkQueue = [[ASINetworkQueue alloc] init]; 
    } 
    failed = NO; 
    [networkQueue reset]; 
    [networkQueue setRequestDidFinishSelector:@selector(requestForDownloadOfFileFinished:)]; 
    [networkQueue setRequestDidFailSelector:@selector(requestForDownloadOfFileFailed:)]; 



    [networkQueue setShowAccurateProgress:YES]; 
    [networkQueue setDelegate:self]; 
    self.request=nil; 

    NSURL *url; 

    NSString *[email protected]"http://www.digitalreview.ca/cams/pics/DSCN0044.JPG"; 
    url = [NSURL URLWithString:urlString]; 
    request = [ASIHTTPRequest requestWithURL:url]; 
    NSString *Filename = [urlString lastPathComponent]; 

    [request setDownloadProgressDelegate:imageProgressIndicator1]; 
    [request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]]; 
    [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]]; 
    [request setShouldContinueWhenAppEntersBackground:YES]; 
    [request setDelegate:self]; 
    [request setDidReceiveDataSelector:@selector(request:didReceiveBytes:)]; 
    [request setShowAccurateProgress:YES]; 

    [networkQueue addOperation:request]; 


    [networkQueue go]; 

} 
- (void)requestForDownloadOfFileFinished:(ASIHTTPRequest *)request1 
{ 

    NSLog(@"req finish........."); 
    NSLog(@"Content will be %llu bytes in size",[request1 contentLength]); 

    goButton.hidden=YES; 
    [imageProgressIndicator1 removeFromSuperview]; 
    UIImage *img = [UIImage imageWithContentsOfFile:[request1 downloadDestinationPath]]; 
    array=[[[NSMutableArray alloc]init]autorelease]; 
    [array addObject:img]; 
    image = [[UIImage alloc ]initWithData:[request1 responseData]]; 


    NSString *receivedString = [request1 responseString]; 
    NSLog(@"received string %@",receivedString); 
    NSData *responseData = [request1 responseData]; 

    NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    NSLog(@"Server response:%@", response); 

    NSLog(@"response data %@",[request1 responseData]); 
    NSLog(@"download destination path %@",[request downloadDestinationPath]); 
    NSLog(@"download destination path1 %@",[request1 downloadDestinationPath]); 
    NSLog(@"image %@",img); 
    NSLog(@"image1 %@",image); 
    if (img) { 
     [imageView1 setImage:img]; 
    } 
    UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Download" message:@"Download Completed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
    [alertView show]; 
    //completed=true; 
    NSLog(@"mutablearray count %@",[array objectAtIndex:0]); 


} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 
(NSIndexPath *)indexPath 
//------------------------------------------------------------------------------- 
{ 
    int tablePadding = 40; 
    int tableWidth = [self.tblViewDownload frame].size.width; 
    if (tableWidth > 480) { 
    tablePadding = 110; 
    } 

    static NSString *CellIdentifier = @"TypeCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero]autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    if([indexPath row]==0) 
    { 
     NSString *[email protected]"http://www.digitalreview.ca/cams/pics/DSCN0044.JPG"; 

     NSString* theFileName = [urlString lastPathComponent]; 

     NSLog(@"%@ the filename",theFileName); 

     goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [goButton setTitle:@"Go" forState:UIControlStateNormal]; 
     [goButton sizeToFit]; 
     [goButton setFrame:CGRectMake(220,30,50,30)]; 

     [goButton addTarget:self action:@selector(fetchThreeImages1:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell addSubview:goButton]; 

    //------------- 
    NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:theFileName]; 
    NSLog(@"%@ workSpacePath ",workSpacePath); 
    if (workSpacePath){ 

     NSLog(@"%@ workSpacePath ",workSpacePath); 

     //-------------- 
     UIImage *imgBack = [UIImage imageNamed:@"btn-back.png"]; 
     imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,20,20)] autorelease]; 
     [imageView1 setBackgroundColor:[UIColor grayColor]]; 

     //imageView1.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]]; 
     imageView1.image = [UIImage imageWithContentsOfFile:workSpacePath]; 
     [cell addSubview:imageView1]; 

     NSLog(@"dfdfD"); 
     NSLog(@"sdfdsf"); 
    } 



    imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease]; 
    [cell addSubview:imageProgressIndicator1]; 

    } 
    NSUInteger imageWidth = (tableWidth-tablePadding-20)/3; 
    NSUInteger imageHeight = 35; 
    [imageView1 setFrame:CGRectMake(tablePadding/2,20,imageWidth,imageHeight)]; 
    [imageProgressIndicator1 setFrame:CGRectMake(120,40,imageWidth,20)]; 

    } 

    return cell; 
} 

답변

1

ASIHTTPRequest 문서 섹션 'Tracking download progress for a set of requests'을 살펴보십시오.

기본적으로 ASINetworkQueue을 만들고 각 요청을 추가해야합니다. 대기열은 전체 진행 상황을 추적하고 진행률 표시 줄을 업데이트 할 수있는 대리자 메서드를 호출합니다.