我目前正在用AFNetworking替换ASIHTTP代码。我有一个场景,我有多个文件要与服务器同步。我希望此任务在后台继续执行,并且我注意到当我在后台时,下载正在进行。我只是好奇和困惑,如果我需要做任何额外的调用来支持后台下载。
我在一个线程上发现了以下内容。
__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
[application endBackgroundTask:backgroundTaskIdentifier];
[[NordecaAFAPIClient sharedClientWithBaseURL:[ECUserDefaults getNordecaApiURL]].operationQueue cancelAllOperations] ;
}];为了支持后台下载,我到底需要写些什么?
我的另一个问题是,在AFDownloadRequestOperation中找到的shouldResume标志是什么意思
发布于 2012-12-13 14:32:04
和在Does AFNetworking have backgrounding support?中一样,AFURLConnectionOperation现在已经支持setShouldExecuteAsBackgroundTaskWithExpirationHandler:,它基本上为你做后台下载管理,因为它的性能和applicationDidEnterBackground中的普通UIBackgroundTaskIdentifier代码一样,就像你在问题中写的那样。
关于AFDownloadRequestOperation中的shouldResume,它是一个符号,表示当文件临时下载到一个“不完整”文件夹时,这是一个临时路径,所以当计算已经下载的数据大小以便知道从哪里恢复下载时,它将返回一个正确的范围。
https://stackoverflow.com/questions/13680848
复制相似问题