AFNetworking/AFNetworking — pull request #1792 by robertmryan (2014-02-03 03:19:52+00:00)
Title: Multiple tasks in conjunction with background NSURLSessionConfiguration if the app terminated

I spent some time tracking down the failure of AFURLSessionManager to properly handle resuming of tasks submitted to a background session if the app terminated. Specifically, if I had a dozen tasks in progress when the app was terminated, when the app was automatically restarted when the tasks finished, I would only see the first one run.

It appears that the issue is that `URLSession:task:didCompleteWithError:` was attempting to remove the observer for the task (but if the app terminated, there was no observer to remove when the app was restarted). I'm not sure if checking to see if `delegate` was not `nil` is really the most elegant way of checking for this scenario (I might be inclined to have a property that indicates whether the observer had been added, or perhaps checking `observationInfo`), but I wanted to make my edits as unobtrusive as possible.

Finally, I added a warning comment to `downloadTaskWithRequest:progress:destination:completionHandler:` documentation (or, more accurately, the .h file) so that future developers are given advance warning that they should be apprehensive about relying on these blocks when, if the app is terminated, these blocks will be lost.