AFNetworking 2 and background tasks

2019-08-04 07:41发布

问题:

I have a question about AFNetworking 2 and background downloads/uploads thanks to the new iOS7 NSURLSession background requests

Is this automatically handled by my AFHTTPRequestOperationManager ? Does it automatically set my requests'session to background mode? I saw that the AFURLSessionManager Has a setDidFinishEventsForBackgroundURLSessionBlock Method but I wonder if everything is automatic?

If my app is killed or suspended, will requests keep on going? How can I get a callback when my app is relaunched?

Thanks a lot for your help!

回答1:

AFHTTPRequestOperationManager uses the old NSURLConnection so that doesn't facilitate background downloading.

AFURLSessionManager uses NSURLSession under the hood so that does. I think you still need to configure the NSURLSession appropriately.

"The NSURLSession class supports background transfers while your app is suspended. Background transfers are provided only by sessions created using a background session configuration object (as returned by a call to backgroundSessionConfiguration:)."

Suggested reading:URL Loading System