O'Reilly logo

iOS and OS X Network Programming Cookbook by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required