저는 동시에 비동기 (델리게이트, 블록이 아님) 인 NSURLConnections
을 실행 중이며, LAN 서버를 공격 할 때 매우 빠르게 돌아옵니다.NSURLConnection이 실행되지 않거나 시간이 초과되지 않습니다.
가끔씩 하나의 NSURLConnection
은 사라지고 절대로 돌아 오지 않습니다.
connection:willSendRequest:
이라고 부르지 만 connection:didReceiveResponse:
(실패)이 아닙니다.
아이디어가 있으십니까? 대신 CFNetwork
을 사용하여 간단한 드롭 인 대체를해야하는지 궁금합니다.
편집 : 표시 할 코드가 많지 않습니다. 내가 한 것은 파일을 다운로드하는 래퍼 클래스를 만든 것입니다. 나는 문제가 덜 때 내가 별도의 대기열에 연결을 실행하지만, 일어날 것입니다 -하지만 여전히 발생합니다.
내가하고있는 일반적인 요점은 각 셀에 대한 다운로드 요청을 테이블 뷰 스크롤 (cellForRowAtIndexPath
)에서 스크롤 한 다음 셀이 여전히 보이면 비동기 적으로 이미지 파일에서 이미지 파일로로드하는 것입니다. 요청한 바와 같이
_request = [NSMutableURLRequest requestWithURL:_URL];
_request.cachePolicy = NSURLRequestReloadIgnoringCacheData;
_request.timeoutInterval = _timeoutInterval;
if(_lastModifiedDate) {
[_request setValue:[_lastModifiedDate RFC1123String] forHTTPHeaderField:@"If-Modified-Since"];
}
_connection = [[NSURLConnection alloc] initWithRequest:_request
delegate:self
startImmediately:NO];
[_connection start];
, 인스턴스 변수 :
NSMutableURLRequest *_request;
NSURLConnection *_connection;
위임 방법 :
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
NSLog(@"%@ send", _URL);
return request;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"%@ response", _URL);
_response = (id)response;
// create output stream
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
_receivedLength += data.length;
_estimatedProgress = (Float32)_receivedLength/(Float32)_response.expectedContentLength;
[_outputStream write:data.bytes maxLength:data.length];
// notify delegate
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// close output stream
// notify delegate
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@ failure", _URL);
// notify delegate
}
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if(_credential && challenge.previousFailureCount == 0) {
[[challenge sender] useCredential:_credential forAuthenticationChallenge:challenge];
}
}
당신이 제발 당신 코드의 자세한 내용을 제공 할 수 있습니까? Btw, NSURLConnection도 비슷한 문제가 있습니다. 당신과 내 사이의 공통점을 찾을 수 있습니까 [여기] (http://stackoverflow.com/questions/17848290/nsurlconnection-doesnt-receive-data-when-creating-many-downloading-objects-in-i) – Envil
표시하십시오 '_request'와'_connection'에 대한 선언, 그리고 당신의 델리게이트 메소드 (아래로 벗겨 낸). 방법으로 '대의원'은 무엇입니까? View Controller입니까, 다른 객체입니까? –
이 토론에서는 본질적으로 '자기'입니다. 내 래퍼 개체 NSURLConnection 내 개체를 유지하지 않는 약한 프록시를 사용하는 옵션이 있습니다. 이 플래그는이 경우 꺼져 있습니다. – xtravar