Downloading a file using MKNetworkKit

In the previous recipe, we saw how to upload a file using MKNetworkKit. In this recipe we will be downloading a file from the Internet. Since all of MKNetworkKit's functionality is encapsulated within the MKNetworkEngine and MKNetworkOperation classes, we need to create an engine first.

We will be using the downloadFileAtPath: method of the MKNetworkOperation class to download the file at the specified path. We will then add the addDownloadStream: callback to our MKNetworkOperation object. This callback will write the file to a stream.

While this recipe downloads an image, we can use the same methods to download any type of file.

Getting ready

This recipe is compatible with both iOS and OS X. We need to download ...

Get iOS and OS X Network Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.