Episode #14

Tracking Download Progress

6 minutes
Published on May 3, 2012

This video is only available to subscribers. Get access to this video and 573 others.

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.

Links

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", 
                                   totalBytesRead,
                                   totalBytesExpectedToRead];
                self.progressLabel.text = label;
            });
        }
    }];