Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Downloading files with a progress bar


AFNetworking includes a UIProgressView+AFNetworking category that makes it easy to add a progress bar to either an upload or download session task. In this recipe, we will create the NSURLSessionDownloadTask using AFNetworking and then add a progress bar to show the progress of the download.

Getting ready

You will need to download and add AFNetworking to your project. You will also need to include the UIProgressView+AFNetworking class from the UIKit+AFNetworking directory into your project. The UIKit+AFNetworking files are included when you download AFNetworking.

How to do it…

Let's look at how we would add a progress bar to our projects.

Creating the download task

The download task will simply download a large file from the Internet:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    NSURLRequest...