我正在从UIGridViewCells下载电影文件。我的代码是:使用AFNetworking下载多个文件时收到内存警告
NSMutableURLRequest* rq = [[APIClient sharedClient] requestWithMethod:@"GET" path:[[self item] downloadUrl] parameters:nil];
[rq setTimeoutInterval:5000];
_downloadOperation = [[AFHTTPRequestOperation alloc] initWithRequest:rq] ;
_downloadOperation.outputStream = [NSOutputStream outputStreamToFileAtPath:[[self item] localUrl] append:NO];
__weak typeof(self) weakSelf = self;
[_downloadOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", [weakSelf.item localUrl]);
[Helper saveItemDownloaded:weakSelf.item.productId];
weakSelf.isDownloading = NO;
[weakSelf.progressOverlayView removeFromSuperview];
[weakSelf setUserInteractionEnabled:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
[weakSelf.progressOverlayView removeFromSuperview];
[weakSelf setUserInteractionEnabled:YES];
weakSelf.isDownloading = NO;
}];
[_downloadOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float progress = totalBytesRead/(float)totalBytesExpectedToRead;
weakSelf.progressOverlayView.progress = progress;
}];
[[NSOperationQueue mainQueue] addOperation:_downloadOperation];
而且在ItemCell的属性是:
@property (nonatomic, retain) AFHTTPRequestOperation *downloadOperation;
后1-2成功下载(20MB),我收到内存警告。每次下载都会增加内存使用量,下载完成后永远不会降低。
从仪器:每个文件
你在做这一切吗? –
对于下载操作,是的。但我发了一个列表来播放电影。 – Burak