Так что я в ситуации, когда я загрузил несколько видеофайлов в приложении iOS, прежде чем перейти на главный экран, и я использую для этого AFNetworking 2. Если мне нужно загрузить один файл, все будет в порядке, но когда мне придется загружать несколько файлов, некоторые сбой с этой ошибкой, это не всегда одни и те же файлы, это кажется случайным ..:Цикл загрузки AFNetworking теряет аутентификацию
Ошибка: ошибка домена = com.alamofire.error.serialization.response Код = -1011 «Ошибка запроса: неавторизованная (401)» UserInfo = 0x7ff943f4fcb0 {NSLocalizedDescription = Запрос не выполнен: неавторизованный (401), com.alamofire.serialization.response.error.response =
Say Я использую этот код:
MainView *mainViewController = [[MainView alloc] init];
NSURLCredential *credential = [NSURLCredential credentialWithUser:AUTH_USERNAME2 password:AUTH_PASSWORD2 persistence:NSURLCredentialPersistenceForSession];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager changeCurrentDirectoryPath:self.topVideoPath];
__block int countVideos = 0;
__block int totalvideos = [videoItems count];
for (int i = 0; i < [videoItems count]; i++){
NSLog(@"dict array : %@" , self.dictArray);
NSMutableDictionary *itemDict = [self.dictArray objectAtIndex:i];
NSURL *url = [NSURL URLWithString:[itemDict objectForKey:@"video"]];
NSString *videoString = [itemDict objectForKey:@"video"];
NSString *specificPath = [[fileManager currentDirectoryPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.dat", [itemDict objectForKey:@"id"]]];
TopItem *item = [videoItems objectAtIndex:i];
if (![videoString isEqualToString:@""]) {
[fileManager changeCurrentDirectoryPath:self.topVideoPath];
NSString *moviePath = [[fileManager currentDirectoryPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"Movie%@.mp4", [itemDict objectForKey:@"id"]]];
NSString *correctMoviePath = [NSString stringWithFormat:@"KyoskSkeleton/TopVideo/Movie%@.mp4", [itemDict objectForKey:@"id"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:url]];
[operation setCredential:credential];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:moviePath append:NO];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float progress = ((float)totalBytesRead)/totalBytesExpectedToRead;
NSLog(@"The downloading progress : %f", progress);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
countVideos = countVideos + 1;
NSLog(@"specific path : %@", specificPath);
[NSKeyedArchiver archiveRootObject:item toFile:specificPath];
if (countVideos == totalvideos){
mainViewController.topScrollViewContent = self.topScrollViewContent;
if ([self.responseDelegate respondsToSelector:@selector(pushController:)]) {
[self.responseDelegate performSelector:@selector(pushController:) withObject:mainViewController];
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Not Downloaded");
NSLog(@"Error : %@", error);
countVideos = countVideos + 1;
}];
[operation start];
}
}
кто-нибудь знает, что происходит не так?
Заранее благодарен!