Progress bar when loading an image

How can I add a progress bar to download a large image or any file? 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];
+3
source share
2 answers

You can override the connection: didReceiveData: in an NSURLConnection call. See here for more details:

How to integrate NSURLConnection with UIProgressView?

+1
source

Run the selector in the background, which checks the image load size and compares it with the desired size. Then set% progress bar to load / required.

0
source

Source: https://habr.com/ru/post/1751643/


All Articles