user1228074
user1228074

Reputation: 61

Progress bar while downloading files iOS

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!!

Upvotes: 6

Views: 7577

Answers (2)

richy
richy

Reputation: 2815

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

Upvotes: 8

Nils Munch
Nils Munch

Reputation: 8845

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

Upvotes: 8

Related Questions