AFNetworking で 500 Mo を超えるファイルをダウンロードする必要があります。それらのダウンロードに 10 分以上かかる場合があり、アプリがバックグラウンドにある場合はダウンロードを完了できません。
そこで、部分ダウンロードを試してみたいと思います。多くのリンクを見つけましたが、これは 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)それを行う良い方法ですか?2) レジュームは outputStream を変更する必要がありますか (append: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];
}
ご協力いただきありがとうございます。