6

I am using the following to download the files from the internet:

NSData *myXMLData1 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"Link]];

Now, I would like to put a progress bar while the download is going on. I checked various posts but i am not able to find out how to do it exactly.

Please help me!!

user1228074
  • 61
  • 1
  • 3
  • Go through http://stackoverflow.com/questions/2267950/how-to-make-an-progress-bar-for-an-nsurlconnection-when-downloading-a-file – Nazik May 07 '12 at 11:03
  • @Azik But, I am also having some problem in How to use NSURLConnection. The link you gave is after I use NSURLConnection to download my files? – user1228074 May 08 '12 at 10:36

2 Answers2

8

I would recommend looking into the ASIHTTP library, which contains a lot of usefull classes on mobile handling and download handling.

Here is a link where they describe what ASIHTTP can offer in terms of download progress tracking : http://allseeing-i.com/ASIHTTPRequest/How-to-use#progress

Nils Munch
  • 8,805
  • 11
  • 51
  • 103
8

add

expectedBytes = [response expectedContentLength];

to

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response

and add

float progress = ((_bytesReceived/(float)_expectedBytes)*100)/100;

to

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data

then setProgress: on your UIProgressView

From: http://www.developers-life.com/progress-bar-download-file-on-iphone.html

richy
  • 2,716
  • 1
  • 33
  • 42