2014-03-28 5 views
0

서버에서 이미지 배열을 다운로드하는 데 문제가 있습니다. 서버에 100 개의 이미지가있는 경우 "AFImageRequestOperation"을 사용하여 모든 이미지를 다운로드해야하며 일부 이미지는 성공적으로 다운로드되지만 많은 이미지가 다운로드되어야 함을 의미합니다.AFImageRequestOperation에서 시간 초과 값을 설정하는 방법

NSURL *url = [NSURL URLWithString:kBaseURLString]; 
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 
[httpClient setAuthorizationHeaderWithUsername:[[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultKeyUsername] 
             password:[[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultKeyPassword]]; 

for(int i = 0; i < [self.downloadImageList count]; i++) { 

    NSString *filename = [[NSString alloc] initWithString:[self.downloadImageList objectAtIndex:i]]; 
    NSMutableURLRequest *urlRequest = [httpClient multipartFormRequestWithMethod:@"POST" 
                      path:@"/xxx/yyyyyyyyyy/getImage" 
                     parameters:nil 
                 constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { 

                  [formData appendPartWithFormData:[filename dataUsingEncoding:NSUTF8StringEncoding] 
                         name:kFormNameFile]; 

                 }]; 

    AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; 
    [requestOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { 

     [self updateSyncClientUIDelegateProgress:(totalBytesRead/totalBytesExpectedToRead) andLabel:@"Downloading Images"]; 
    }]; 

    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 


     if([[urlRequest URL] isEqual:[[operation request] URL]]) { 

      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
       UIImage *image = responseObject; 
       NSLog(@"Downloading image %@",image); 

       [UIImagePNGRepresentation(image) writeToFile:[syncedImagesPath stringByAppendingPathComponent:filename] atomically:YES]; 
      }); 

     } 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

     if([[operation response] statusCode] == 404) { 
      return; 
     } 
     NSLog(@"failure BLOCK %@",error); 
     NSLog(@"failure error code %ld",(long)[error code]); 



     if([error code] != NSURLErrorCannotDecodeContentData) { 

      [self cancelSyncFromFailure]; 
     } 

    }]; 

제발 도와주세요 : 내가 다운로드 이미지 follwing을 방법을 사용하여

이미지 때문에 서버에서 "시간 초과"오류, 내가 큰 사이즈의 이미지 (3.mb)와 마주 시간 초과 문제의 다운로드에 실패하는 큰 iamges를 다운로드하는 동안이 시간 초과 문제를 해결하려면

답변

0

TimeOut Request Time (시간 초과 요청 시간)을 다음과 같이 설정하십시오.

[urlRequest setTimeoutInterval:50]; 
+0

을 NOW.TRY 나에게 "요청 시간 초과"메시지를 전송하지만 아니었다 FINE.FIRSTLY 일하고 솔루션입니다 실제로 서버에서 오류가 발생했습니다. 오류 : 오류 도메인 = NSURLErrorDomain 코드 = -1001 "요청 시간이 초과되었습니다." UserInfo = 0x12830130 {NSErrorFailingURLStringKey = http : //xxxxx.com/yyyy/httpbroker/getImage, NSErrorFailingURLKey = http : //xxxxx.com/yyyyy/httpbroker/getImage, NSLocalizedDescription = 요청 시간이 초과되었습니다. NSUnderlyingError = 0xe351d60 "요청 시간 초과되었습니다. "} 오류 오류 코드 -1001 – karthick

1

지금 여기 내가 사용하고 또한 여전히 같은 문제에 직면 본

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:photourl] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:10000]; 

AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; 
    [requestOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { 

    ...... YOUR CODE 
}]; 
관련 문제