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 the framework from https://github.com/MugunthKumar/MKNetworkKit and add it to our project. We also need to add the following four frameworks:
ImageIO.framework
Security.framework
SystemConfiguration.framework
CFNetwork.framework
How to do it…
Let's create...