Better way to fetch JSON data from a server from iOS app
NSURLSession was designed from the ground up to be as similar to NSURLConnection as possible, so that those accustomed to using the latter will have no problem transitioning to the former.  Meanwhile, NSURLSession has a lot of major advantages over NSURLConnection.  

First of all, we can get rid of all the code for dispatching on a background thread.  NSURLSession works on background threads automatically unless we specify otherwise.

We still have to create our NSURLRequest.  I don't know any way around this.

But once we've got our request set up, and remember, all of this is outside the GCD block, we just do this:

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

[[session dataTaskWithRequest:request 
            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    // do stuff

}] resume];


As you can see, it's quite similar to NSURLConnection.  We replace // do stuff with the stuff we want to do when the request is complete (completion handler).  We have our data, our response, and our error all in this block.

A lot of the new power from NSURLSession comes from the NSURLSessionConfiguration object.  Using NSURLSessionConfiguration, we can easily set up downloads/uploads to happen in the background (when our app is not open).  We can specify to only run on Wi-Fi and not use cellular data as setting a BOOL.  We can set a BOOL to tell the OS to only try doing our background uploads/downloads when the device is on Wi-Fi and plugged into a power source.  

NSURLSessionConfiguration also has an HTTPAdditionalHeaders property, which is an NSDictionary object containing additional headers that should be sent with requests using this configuration.

There's a lot more information about NSURLSessionConfiguration here.