Reputation: 9722
I'm using the AFNetworking framework to download files and write them to the local file system.
But since the files can be quite big I want to add a UIProgressView
, but I can't seem to find any method that gets updated with the progress.
I see people talking about setProgressBlock, but I can't find any information about this in the docs: http://afnetworking.org/Documentation/Classes/AFHTTPRequestOperation.html
Is there a method that does this? I'm just using AFHTTPRequestOperation
to download the files.
Upvotes: 3
Views: 11431
Reputation: 31294
The setDownloadProgressBlock
method is part of AFURLConnectionOperation
, from which AFHTTPRequestOperation
inherits - that's why you don't see it in the AFHTTPRequestOperation
documentation. The documentation you're after is here:
http://cocoadocs.org/docsets/AFNetworking/1.3.1/Classes/AFURLConnectionOperation.html
Upvotes: 9
Reputation: 9600
refer a following code. this is a some file download using a AFNetworking Code.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://blahblah.com/blahblah.mp3"]];
AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [paths objectAtIndex:0] stringByAppendingPathComponent:@"blahblah.mp3"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead)
{
myProgressView.progress = (float)totalBytesRead / totalBytesExpectedToRead;
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"downloadComplete!");
}];
[operation start];
Upvotes: 15