2012-07-23 3 views
0

서버에서 음악 파일 m4a를 다운로드하는 iPad 앱이 있습니다. AFHTTPRequestOperation을 사용하여 outputStreamToFileAtPath 내 문서로 직접 다운로드합니다. 나는 그것이 얼마나 오래 걸리는지 걱정하지 않는다. 다운로드가 몇 시간 후에 일어날 가능성이 높기 때문에 다운로드 한 파일 만 있으면됩니다. 내 ipad에서 실행하려고하면 다음과 같은 오류 메시지가 나타납니다. 나는 처음 5 개와 5 개를 얻지 만 나머지는 타임 아웃한다. 내 코드에 문제가 있습니까? 제한 시간 값을 늘릴 수있는 방법이 있습니까? 아니면 내가 AFNetworking 외에 사용할 수있는 다른 것이 있습니까? 어떤 도움이나 아이디어라도 대단히 감사하겠습니다. AFNetworking이 ios iPad에서 여러 m4a 파일을 다운로드 할 수 없습니다.

ERROR ERROR ERROR:Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0xc6e01c0 {NSErrorFailingURLStringKey=http://xxxx/Music/ece0b7c5ab71a24c6f6694986fc7a4a7.m4a, NSErrorFailingURLKey=http://xxx/Music/ece0b7c5ab71a24c6f6694986fc7a4a7.m4a, NSLocalizedDescription=The request timed out., NSUnderlyingError=0xc69c950 "The request timed out."} - could not save to path:/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]; 
    } 
+0

은 NSOperationQueue를 사용하여 종료되었습니다. 느리지 만 작동합니다. – LittlePeculiar

+0

동일한 상황이 발생하지만 AFNetworking의 AFHTTPClient의 operationQueue를 사용하고 있습니다. 스트리밍 다운로드 작업의 긴 목록을 대기열에 추가 할 때이 중 많은 수가 시간 초과되어 -1001 오류가 발생하는 이유는 무엇입니까? –

+0

NSMutableURLRequest에 [setTimeoutInterval : 900 요청]을 추가했습니다. 이것은 내 문제를 해결했다. 행운을 빕니다. – LittlePeculiar

답변

0
[request setTimeoutInterval:1000]; 

은 요청 생성 후에 추가한다.

관련 문제