Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Regarding progress, see <a href="http://afnetworking.github.com/AFNetworking/Classes/AFURLConnectionOperation.html#//api/name/setDownloadProgressBlock:" rel="nofollow noreferrer"><code>setDownloadProgressBlock</code></a> (part of <code>AFURLConnectionOperation</code>, from which <code>AFHTTPRequestOperation</code> is subclassed), e.g.:</p> <pre><code>[operation setDownloadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { NSLog(@"Sent %d of %d bytes, %@", totalBytesWritten, totalBytesExpectedToWrite, path); }]; </code></pre> <p>And, in your code sample, you're calling <code>setCompletionBlockWithSuccess:failure:</code>, so that provides the status regarding the completion of the individual operations. Personally, in my little test, I just maintain an array of my requested downloads, and have these three blocks (progress, success, and failure) update the status code of my downloads like so:</p> <pre><code>for (NSInteger i = 0; i &lt; 20; i++) { NSURLRequest *request = ... // set the request accordingly // create a download object to keep track of the status of my download DownloadObject *object = [[DownloadObject alloc] init]; download.title = [NSString stringWithFormat:@"Download %d", i]; download.status = kDownloadObjectStatusNotStarted; [self.downloadObjects addObject:download]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { download.status = kDownloadObjectStatusDoneSucceeded; // update my UI, for example, I have table view with one row per download // // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] // withRowAnimation:UITableViewRowAnimationNone]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { download.status = kDownloadObjectStatusDoneFailed; // update UI // // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] // withRowAnimation:UITableViewRowAnimationNone]; }]; [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { download.totalBytesRead = totalBytesRead; download.status = kDownloadObjectStatusInProgress; // update UI // // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] // withRowAnimation:UITableViewRowAnimationNone]; }]; [queue addOperation:operation]; } </code></pre> <p>You can keep track of the individual downloads this way. You can also just keep track of the pending operations (or query the <code>HTTPClient</code> object's <code>operationQueue</code> property, and look at the <code>operationCount</code> property of that).</p> <hr> <p>In terms of downloading 100 files, two considerations:</p> <ul> <li><p>I would have thought that you'd want to call <code>setMaxConcurrentOperationCount</code> on the <code>operationQueue</code> of your <code>HTTPClient</code> subclass, setting it to some reasonable number (4 or 5), as glancing at the AFNetworking code, it doesn't seem to do that. I find that there are diminishing returns if you go much above that, and if all of the files are from a single server, there are constraints on how many concurrent operations can be done between a given client and given server.</p></li> <li><p>I've read anecdotal claims that the Apple will reject apps that make extraordinary requests over cellular network. See <a href="https://stackoverflow.com/a/14922807/1271826">https://stackoverflow.com/a/14922807/1271826</a>. </p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload