我有一个应用程序,其进程读取位于服务器中的.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];
}
}
}
在这里,如何处理这些场景:
- 我有暂停文件下载过程的方法吗?
- 如何处理互联网连接或任何其他中断?