title: iOS Asihttprequest custom progress tracking
body: <p>i'm triyng to show the progress of the download with AsiHttpRequest something like this:
   300 kb / 5 Mb and update constantly the first value.
  I understood that if i use -(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data i need to manage by myself the nsdata object and write by myself the downloaded file </p>
  
  <p>i've tried this but do not works!!
  The mutable data is null!
  i use iOS 5 with ARC.
  Thanks for any help!</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>I solved with this code, i've set delegate to self and every things work correctly.
  Just i do not understand if in this way and with ARC i need to clear the delegate</p>
  
  <pre><code>- (void)dealloc
  {
     [request clearDelegatesAndCancel];
  }
  </code></pre>
  
  <p>Thanks to everybody for the help!!</p>
  
  <p><strong>UPDATED</strong></p>
  
  <pre><code>-(void)downloadFile: (NSString*) file {
             NSString* urlFilePdf = [NSString stringWithFormat:@"http://www.mywebsite.com/%@",file];
  
              myFileName = file;
  
              NSURL *url = [NSURL URLWithString:urlFilePdf];
  
              NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
              NSString *documentsDirectory = [paths objectAtIndex:0];
              NSString *filePath = [documentsDirectory stringByAppendingPathComponent:file];
  
  
              progressAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DOWNLOADFILE",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
  
              progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
              [progressAlert addSubview:progressView];
              [progressView setProgressViewStyle: UIProgressViewStyleDefault];
  
              lblTotal = [[UILabel alloc] initWithFrame:CGRectMake(5, 50, 273, 20)];
              [lblTotal setTextAlignment:UITextAlignmentCenter];
              [lblTotal setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:14.0]];
              [lblTotal setTextColor:[UIColor whiteColor]];
              [lblTotal setBackgroundColor:[UIColor clearColor]];
              [progressAlert addSubview:lblTotal];
  
              requestFile = [ASIHTTPRequest requestWithURL:url];
              [requestFile setDelegate:self];
              [requestFile setDownloadDestinationPath:filePath];
              [requestFile setDownloadProgressDelegate:self];
              [requestFile setShowAccurateProgress:YES];    
              [progressAlert show];
  
              [requestFile startAsynchronous];
  
  }
  
  - (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength
  {
      NSLog(@"%@",[NSString stringWithFormat:@"incrementDownloadSizeBy %quKb", newLength/1024]);
  }
  
  - (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
  {
      NSLog(@"%@",[NSString stringWithFormat:@"didReceiveBytes %quKb", bytes/1024]);
      currentLength += bytes;
      [lblTotal setText:[NSString    stringWithFormat:@"%quKb/%@",currentLength/1024,self.TotalFileDimension]];
  }
  
  - (void)setProgress:(float)newProgress {
      NSLog(@"%f",newProgress);
      progressView.progress = newProgress;
  }
  
  
  -(void) requestFinished:(ASIHTTPRequest *)request
  {
      // code ...
  }
  
  -(void) requestFailed:(ASIHTTPRequest *)request
  {
      // code ...
  }
  
  - (void)dealloc
  {
     [request clearDelegatesAndCancel];
  }
  </code></pre>