I'm a little confused about how to take advantage of the new iOS 7 NSURLSession and AFNetworking migration features (versions 2 and 3).
I saw a WWDC 705 - What's New in Foundation Networking session WWDC 705 - What's New in Foundation Networking , and they demonstrated a background load that continues after the application terminates or even crashes.
This is done using the new API application:handleEventsForBackgroundURLSession:completionHandler: and the fact that the session delegate will eventually receive callbacks and can complete its task.
So, I am wondering how to use it with AFNetworking (if possible) to continue downloading in the background.
The problem is that AFNetworking conveniently uses the block API to execute all requests, but if the application terminates or crashes, these blocks also disappeared. So how can I complete the task?
Or maybe I missed something ...
Let me explain what I mean:
For example, my application is a photo-sharing application, let's say that I have a PhotoMessage object that represents a single message, and this object has properties such as
state - describe the state of loading photos.resourcePath - path to the final uploaded photo file.
Therefore, when I receive a new message from the server, I create a new PhotoMessage object and start loading its resource.
PhotoMessage *newPhotoMsg = [[PhotoMessage alloc] initWithInfoFromServer:info]; newPhotoMsg.state = kStateDownloading; self.photoDownloadTask = [[BGSessionManager sharedManager] downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { NSURL *filePath =
As you can see, I use the completion block to update this PhotoMessage object in accordance with the response received.
How can I accomplish this using background wrapping? This completion block will not be called, and as a result, I cannot update newPhotoMsg .
ios objective-c afnetworking afnetworking-2
Mario Jan 25 '14 at 11:48 2014-01-25 11:48
source share