NSURLSession basics

ref – http://code.tutsplus.com/tutorials/networking-with-nsurlsession-part-1–mobile-21394

http://code.tutsplus.com/tutorials/networking-with-nsurlsession-part-2–mobile-21581

1) Simple GET of data

2) Downloading a file using NSURLSessionDownloadDelegate protocol

So we want to download a file. However, we want to see what percentage we are at, as well as when the file has finished downloading.

A session configuration object is nothing more than a dictionary of properties that defines how the session it is tied to behaves. A session has one session configuration object that dictates cookie, security, and cache policies, the maximum number of connections to a host, resource and network timeouts, etc.

Once a session is created and configured by a NSURLSessionConfiguration instance, the session’s configuration cannot be modified. If you need to modify a session’s configuration, you have to create a new session. Keep in mind that it is possible to copy a session’s configuration and modify it, but the changes have no effect on the session from which the configuration was copied.

Once a session is created and configured by a NSURLSessionConfiguration instance, the session’s configuration cannot be modified. A SessionConfiguration is immutable. If you need to modify a session’s configuration, you have to create a new session. Keep in mind that it is possible to copy a session’s configuration and modify it, but the changes have no effect on the session from which the configuration was copied.

  1. Use a private UIImageView to hold the image
  2. privately conform to NSURLSessionDownloadDelegate protocol
  3. Implement protocol methods
ViewController.m

Add the image holder to your view hierarchy

Then use a NSURLSession to get a task running

Notice that we first get a default Session Configuration object. Then we pass it into the session to be used.

Configuring a session configuration object is as simple as modifying its properties as shown in the example. We can then use the session configuration object to instantiate a session object. The session object serves as a factory for data, upload, and download tasks, with each task corresponding to a single request.

Finally, implement the protocol methods

Make sure you use the main queue, to update your image holder with the data you just downloaded.

Also, if you are to use a progress view to show updates on progress, make sure you dispatch a code block onto the main queue, so that the main thread can run the code and show it.

http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http