views:

89

answers:

2

Hello - How would I go about adding a progress bar for downloading a large image, or any file for that matter? here is my code:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);

        NSString *docsPath = [paths objectAtIndex:0];
        NSString *downloadPath = [[[NSString alloc]initWithFormat:@"http://www.zzz.com/%@.jpg",chartFileName]autorelease];
        NSString *savePath = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath, chartFileName]autorelease];
        NSURL *url = [[NSURL alloc]initWithString:downloadPath];
        NSData *downloadedChartData = [NSData dataWithContentsOfURL:url];
        [url release];
        [downloadedChartData writeToFile:savePath atomically:YES];
A: 

Run a selector in the background that checks the image's download size, and compares it against the required size. Then set the % of the progress bar to downloaded/required.

jrtc27
how do i check the sizes?
Brodie
+1  A: 

You could override connection:didReceiveData: in your NSURLConnection call. See here for more:

http://stackoverflow.com/questions/312796/how-to-integrate-nsurlconnection-with-uiprogressviewx

Joost Schuur