How to get remote file size to increment progress bar?
i need to download large pdf from web and i created a progress bar controller.
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?
ThanksI 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.
ASIHTTPRequest has a downloadProgressDelegate
that can handle this for you- its very easy to use.
Solved.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
dimensione = (float)[response expectedContentLength];
NSLog(@"content-length: %f bytes", dimensione);
}
I forget didReceiveResponse
!
good.
精彩评论