サーバーにある.m3u8ファイルを読み取って解析するプロセスを持つアプリケーションがあります。次に、後でチャンク.tsファイルをダウンロードします。AFNetworking 3.x
- (void)downloadChunks:(NSMutableArray *)streamingChunks directoryPath:(NSURL *)path{
for (NSInteger i=0; i<streamingChunks.count; i++) {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *tsDownloadURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", [URL URLByDeletingLastPathComponent], streamingChunks[i]]];
NSURLRequest *request = [NSURLRequest requestWithURL:tsDownloadURL];
self.downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
return [path URLByAppendingPathComponent:[streamingChunks objectAtIndex:i]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
self.progressView.progress += intermediate;
NSLog(@"FilePath: %@", filePath);
}];
if ([AFNetworkReachabilityManager sharedManager].reachable) {
[self.downloadTask resume];
} else {
[self.downloadTask suspend];
}
}
}
ここでは、これらのシナリオを処理する方法:
- ファイルのダウンロード プロセスを一時停止する方法はありますか?
- インターネット接続やその他の中断を処理するにはどうすればよいですか?