AFNetworking/AFNetworking — pull request #1257 by kcharwood (2013-08-26 20:30:29+00:00)
Title: [2.0] Added additional information to AFNetworkingTaskDidFinishNotification

While working on making [AFHARchiver](https://github.com/mutualmobile/AFHARchiver) compatible with 2.0, I noticed that I don't actually have access to the raw response data, or the serialized response object, which is needed in order to produce thorough logs. This pull request attempts to rectify that by adding information to the userInfo dictionary posted with the notification.

While in the code, I noticed a few places where we duplicated code, so I tried to make a few DRY methods in order to reduce maintenance going forward.

Highlights from the PR:

* I can only access the response data and the serialized response from the task completion block of the task creation method (I really feel Apple dropped the ball here), so I had to move the posting of the DidFinishNotification from the KVO method to the completion block of the task.
* I noticed that the data task and upload task completion handler methods were exactly the same, so I moved those into one DRY method.
* The download task completion handlers were also similar to each other, so I've moved those into a single DRY method.
* That task completion methods now properly construct the user info dictionary, and posts the notification.
* I added a DRY method for posting the notification, since it now happens from a few different places.
* I added a DRY method for setting up KVO for a specific task since that happens in a few different places.
* I added a DRY method to tear down KVO for a specific task.
* I noticed a few places where the failure block was not being sent to the main queue. Fixed that in the new DRY methods.

As far as the keys for the user info, the dictionary may contain the following values:

* AFNetworkingTaskDidFinishResponseDataKey: the raw response object
* AFNetworkingTaskDidFinishSerializedResponseKey: the serialized response
* AFNetworkingTaskDidFinishResponseSerializerKey: the response serializer used to serialize the response
* AFNetworkingTaskDidFinishAssetPathKey: the path that response data was downloaded too (for download tasks)
* AFNetworkingTaskDidFinishErrorKey: any error associated with the task.

For `AFHTTPRequestOperations`, all of this information can be obtained from the operation directly. NSURLSessionTask doesnt give us those options, so I feel this is necessary. The above keys give me everything I need in order to implement AFHARciver for 2.0.

Let me know your thoughts.

:beers: