我正在使用AFDownloadRequestOperation。它工作正常,但现在每次运行时都会突然出现此错误(我每次运行时都会从同一个URL下载,并且我会清除AppDelegate中的Documents和Temp文件夹)。
发起下载。 (在下载之前,我会手动检查Temp或Documents文件夹中没有任何内容,即下载完成后我存储文件的位置。)
下载在1-2秒内完成,代码移动到成功块,调试控制台显示206状态代码,一个文件神奇地放在Documents文件夹中,并且具有确切的文件大小(它过去是为了正确下载,直到我开始遇到这个问题)。该文件已损坏,无法打开。
以下是代码段 -
download_operation_progress_block = ^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
float progress = ((float)totalBytesReadForFile) / totalBytesExpectedToReadForFile;
dataFetcherObject.downloadProgressDetails.downloadPercentage = [NSNumber numberWithFloat:floorf(progress*100)];
};
download_operation_success_block = ^(AFHTTPRequestOperation *operation, id responseObject) {
dataFetcherObject.downloadProgressDetails.isDownloadDone = [NSNumber numberWithBool:YES];
dataFetcherObject.isDataFetched = @"Yes";
};
download_operation_failure_block = ^(AFHTTPRequestOperation *operation, NSError *error) {
[dataFetcherObject.downloadProgressDetails.downloadOperation cancel];
dataFetcherObject.isDataFetched = @"Error";
};
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:contentDownloadRequest
targetPath:path
shouldResume:YES];
[operation setCompletionBlockWithSuccess:download_operation_success_block
failure:download_operation_failure_block];
[operation setProgressiveDownloadProgressBlock:download_operation_progress_block];
// operation.deleteTempFileOnCancel = TRUE;
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[operationQueue addOperation:operation];
dataFetcherObject.downloadProgressDetails.downloadOperation = operation;
这可能是什么原因。