我有一个充满了通过我的应用访问的公共文件的存储桶。该应用会使用AFHTTPRequestOperation
通过AFHTTPRequestOperationManager
下载一批这些文件。对于几乎所有用户而言,这可以顺利运行而没有任何问对于极少数用户,所有下载都会因各种错误消息而失败。
大多数错误消息为Request failed: not found (404)
,约5-10%为The operation couldn’t be completed. (NSURLErrorDomain error -999.)
,The operation couldn’t be completed. No such file or directory
和The network connection was lost
。
遇到失败的用户在尝试再次下载文件时会遇到相同的失败,直到他们删除应用并重新安装。具有相同应用程序的其他用户可以毫无困难地下载文件。
以下是用于下载文件的代码:
-(void)beginDownloadsHTTP {
NSString *baseURL = @"https://s3.amazonaws.com/";
_afHTTPManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:baseURL]];
for (int i = 0; i < 5; i++) {
[self downloadOneFileHTTP:_fileKeys.anyObject];
}
}
-(void)downloadOneFileHTTP:(NSString *)oneKey {
[_fileKeys removeObject:oneKey];
NSString *baseURL = @"https://s3.amazonaws.com/";
NSString *plusKey = [oneKey stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSString *downloadURL = [NSString stringWithFormat:@"%@%@/%@", baseURL, _bucketName, plusKey];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
NSString *downloadPath = [self downloadPathForItem:oneKey];
AFHTTPRequestOperation *op = [_afHTTPManager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (_fileKeys.count > 0) {
[self downloadOneFileHTTP:_fileKeys.anyObject];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self fileDidFailWithKey:oneKey andError:error];
}];
op.securityPolicy.allowInvalidCertificates = YES;
op.outputStream = [NSOutputStream outputStreamToFileAtPath:downloadPath append:NO];
[_afHTTPManager.operationQueue addOperation:op];
}
有关导致问题的原因的任何想法?似乎手机中存储了一些设置导致特定文件集始终失败,删除应用程序会清除该设置,但我不知道在哪里查找。