我需要下载文件> 500 Mo与AFNetworking。 有时,下载它们的时间大于10分钟,如果应用程序在后台,则下载无法完成。AFNetworking +大的下载文件+恢复下载
所以我想尝试部分下载。我发现了很多链接,并且这似乎可以通过AFHTTPRequestOperation上的pause()和resume()方法来实现。
其实,我所做的:
[self.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
// Clean up anything that needs to be handled if the request times out
[self.downloadOperation pauseDownload];
}];
DownloadOperation是AFHTTPRequestOperation(单身)的子类。
而且在AppDelegate中:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// resume will only resume if it's paused...
[[DownloadHTTPRequestOperation sharedOperation] resumeDownload];
}
服务器即可得到头的新范围...
我的问题:
1)是-T的好办法吗它呢? 2)简历是否需要更改outputStream(追加:NO => append:YES)?或者 - 它由AFNetworking管理? (没有找到)
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
像这样的东西(在DownloadHTTPRequestOperation):
- (void)pauseDownload
{
NSLog(@"pause download");
[self pause];
}
- (void)resumeDownload
{
NSLog(@"resume download");
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
[self resume];
}
感谢您的帮助。
BTW AFNetworking也是 “非ARC” – pahan
AFNetworking现在启用ARC。 – tangqiaoboy