AFNetworking Background Task

I'm currently working on replacing ASIHTTP code with AFNetworking. I have a scenario where I have multiple files to synchronize with the server. I want this task to continue in the background and I have noticed that the download is progressing when I'm in the background. I'm just curious and confused if I need to do any additional calls to support background downloading.

I found the following on a thread.

__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application   beginBackgroundTaskWithExpirationHandler:^(void) {
    [application endBackgroundTask:backgroundTaskIdentifier];
    [[NordecaAFAPIClient sharedClientWithBaseURL:[ECUserDefaults getNordecaApiURL]].operationQueue cancelAllOperations] ;
}];

What do I really require to write in order to support background dowloading?

The other question I have is that what is meant by the shouldResume flag found in the AFDownloadRequestOperation ?


As in Does AFNetworking have backgrounding support? , AFURLConnectionOperation now already supports setShouldExecuteAsBackgroundTaskWithExpirationHandler: , which basically does the background download management for you, as its performance is just the same as the normal UIBackgroundTaskIdentifier code in applicationDidEnterBackground , like what you wrote in the question.

And with regards to the shouldResume in AFDownloadRequestOperation , it's a symbol indicating that when the file is temporarily downloaded into a "incomplete" folder, which is a temp path, so when computing the already downloaded data size so that to know from where to resume the download, it will return a correct range.

链接地址: http://www.djcxy.com/p/96764.html

上一篇: 如何下载uiimage async

下一篇: AFNetworking后台任务