Tracking Download Progress

Episode #14 | 6 minutes | published on 05/03/2012
Subscribers Only
In this episode, we'll use AFNetworking to track the progress of a file download and display it in a UIProgressView. Once we've downloaded a small movie, we'll play it using MPMoviePlayerViewController.


Tracking Progress with AFNetworking

    [op setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        if (totalBytesExpectedToRead > 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.progressView.alpha = 1;
                self.progressView.progress = (float)totalBytesRead / (float)totalBytesExpectedToRead;
                NSString *label = [NSString stringWithFormat:@"Downloaded %lld of %lld bytes", 
                self.progressLabel.text = label;
blog comments powered by Disqus