У меня есть приложение для iPad, которое загружает музыкальные файлы m4a с сервера. Я использую AFHTTPRequestOperation для загрузки непосредственно в мой документ, находящийся в каталоге outputStreamToFileAtPath. Меня не волнует, сколько времени это займет. Мне просто нужны загруженные файлы, так как загрузка, скорее всего, будет происходить в нерабочее время. Я получаю следующее сообщение об ошибке, когда пытаюсь запустить его на своем iPad. Я получаю первые 5 и последние 5, но затем тайм-аут остальных. Есть ли проблема с моим кодом? Есть ли способ увеличить значение тайм-аута? Или есть что-то еще, что я могу использовать, кроме AFNetworking? Любая помощь/идеи приветствуется.
ERROR ERROR ERROR:Error Domain=NSURLErrorDomain Code=-1001 «Время ожидания запроса истекло». UserInfo = 0xc6e01c0 {NSErrorFailingURLStringKey = HTTP: //xxxx/Music/ece0b7c5ab71a24c6f6694986fc7a4a7.m4a, NSErrorFailingURLKey = HTTP:. //Xxx/Music/ece0b7c5ab71a24c6f6694986fc7a4a7.m4a, NSLocalizedDescription = Запрос тайм-аут, NSUnderlyingError = 0xc69c950 "Запрос тайм-аут" } - не удалось сохранить по пути:/var/mobile/Applications/207B2EFB-78E0-4BB2-8019-026B598ECE44/Documents/music/ece0b7c5ab71a24c6f6694986fc7a4a7.m4a
и код:
- (void)saveFilesToDocDir
{
NSString *fileLink = @"http://xxx/Music/";
NSArray *dirPathSearch = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirPath = [dirPathSearch objectAtIndex:0];
NSString *dirPath = [docDirPath stringByAppendingPathComponent:@"music/"];
// if the sub directory does not exist, create it
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dirPath])
{
NSLog(@"%@: does not exists...will attempt to create", dirPath);
if (![fileManager createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error])
NSLog(@"errormsg:%@", [error description]);
}
self.processCount = 0;
for (int i = 0; i < [self.musicFiles count]; i++)
{
NSString *filename = [self.musicFiles objectAtIndex:i];
NSString *urlPath = [NSString stringWithFormat:@"%@%@", fileLink, filename];
NSString *filePath = [dirPath stringByAppendingPathComponent:filename];
// download the song file and save them directly to docdir
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlPath]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
self.processCount++;
NSLog(@"Song:%d Success!", processCount);
// all the files have been saved, now update the playlist
if (self.processCount == [self.musicFiles count])
{
[self updatePlaylist];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
self.processCount++;
NSLog(@"ERROR ERROR ERROR:%@ - could not save to path:%@", error, filePath);
} ];
[operation start];
}