1

i need to download large pdf from web and i created a progress bar controller.

enter image description here

But, how i set max progress value it i don't know the pdf size before downloading?
Is there a way to get file size and use it to increment progress bar?

I'm using

myPDFremoteUrl = "http://www.xasdaxxssxx.pdf";
- (float) getFileSize {
    NSFileManager *man = [[NSFileManager alloc] init];
    NSDictionary *attrs = [man attributesOfItemAtPath: myPDFremoteUrl error: NULL];
    UInt32 result = [attrs fileSize];

    return (float)result;
}

but i don't able to check remote size in this way...

any idea?
Thanks

elp
  • 8,021
  • 7
  • 61
  • 120

3 Answers3

2

I would use ASIHTTPRequest for your data retrieval. It has progress monitoring built in.

If you really want to stick with what you've got, you can look at the HTTP header. It has a property called "Content-Length" that will help you out.

Good luck.

Aurum Aquila
  • 9,126
  • 4
  • 25
  • 24
  • 1
    ASIHTTPRequest does not work properly in iOS5 and the developer is no longer maintaining the project. I suggest you look elsewhere for this functionality, for instance, CFNetworking. – BBonifield Nov 09 '11 at 00:43
1

ASIHTTPRequest has a downloadProgressDelegate that can handle this for you- its very easy to use.

Luke Mcneice
  • 3,012
  • 4
  • 38
  • 50
0

Solved.

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    dimensione = (float)[response expectedContentLength];

    NSLog(@"content-length: %f bytes", dimensione);
}

I forget didReceiveResponse!

good.

elp
  • 8,021
  • 7
  • 61
  • 120