3

는 다음 코드NSMutableURLRequest "요청 시간 초과"문제. . 사람이 어떻게 저를 제안 할 수 있습니다,

NSURL *url = [NSURL URLWithString:@"my download url string"]; 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.f]; 

NSURLConnection * connection = [NSURLConnection connectionWithRequest:request delegate:self]; 

[connection start]; 

를 사용하여 내 응용 프로그램에서 데이터를 다운로드하려고하지만 문제는 몇 번 내가 다음과 같은 오류 때문에

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1d5be240 
{NSErrorFailingURLStringKey=http://dr282zn36sxxg.cloudfront.net/datastreams/f- 
d%3Afc7f649e1e3ba58452f67e3fa1f66f69a15b96b3ea585c946e4fa854%2BEPUB%2BEPUB.1, 
NSErrorFailingURLKey=http://dr282zn36sxxg.cloudfront.net/datastreams/f- 
d%3Afc7f649e1e3ba58452f67e3fa1f66f69a15b96b3ea585c946e4fa854%2BEPUB%2BEPUB.1, 
NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1e1975b0 "The request 
timed out."} 

을 얻고있다 이것을 해결하십시오. . .

+0

다운로드하려는 데이터 종류는 무엇입니까? –

+0

@iOSCoder 오류 메시지를 보시오;) – HAS

+0

@iOSCoder 확장자가 .epub 인 파일 –

답변

4

150 초와 같이 시간 초과 간격을 늘리십시오.

0

그냥 요청을 다시 보내십시오 :) 또는 요청 제한 시간 간격을 120 초와 같이 길게 만듭니다.

0

오류 메시지에 요청 시간이 초과 되었음이 분명하게 표시됩니다. 네트워크 속도가 향상되거나 요청 시간이 길어지면 이미지 다운로드에 충분하지 않을 수 있습니다.

:

+0

이미지 다운로드가 아닙니다.) – HAS

+2

현재 NSURLConnection 구현에서 연결에 "timeoutInterval"초 * 비활성이있을 때 시간 초과가 발생합니다. 즉, 데이터가 천천히 들어올지라도 "timeoutInterval"초마다 적어도 한 바이트 씩 (지정된대로 60 초)이 지나면 시간 초과되지 않아야합니다. – CouchDeveloper

1

[NSURLConnection sendAsynchronousRequest:queue:completionHandler:라고 GCDs 추상화를 사용해보십시오

NSURL *url = [NSURL URLWithString:@"your_URL"]; 
NSURLRequest *myUrlRequest = [NSURLRequest requestWithURL:url]; 
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest: myUrlRequest queue: queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 

    if ([data length] > 0 && error == nil) 
     //doSomething With The data 

    else if (error != nil && error.code == ERROR_CODE_TIMEOUT) 
     //time out error 

    else if (error != nil) 
     //download error 
}]; 

는 IT가 어떠한 효과를 내고 있는가?