HTTP 요청을 통해 웹 서버에서 파일 [> 40MB]을 다운로드하려고합니다. 이를 위해 Apple에서 제공 한 SimpleURLConnection 샘플을 사용했습니다. 이 샘플에서는 이미지 파일 만 다운로드하기 때문에 코드를 수정하여 pdf 파일을 다운로드하고 응용 프로그램의 문서 디렉토리에 저장했습니다. 작은 파일을 다운로드하는 데 문제가 없지만 대용량 파일 [> 40MB]을 다운로드하려는 경우에만 6.4MB의 데이터를 다운로드합니다. 참고로iOS에서 대용량 파일을 다운로드하는 방법은 무엇입니까?
,
감사합니다, 제가이 문제를 해결하는 데 도움하십시오코드를 다운로드하는 데이터
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
// A delegate method called by the NSURLConnection as data arrives. We just
// write the data to the file.
{
#pragma unused(theConnection)
NSInteger dataLength;
const uint8_t * dataBytes;
NSInteger bytesWritten;
NSInteger bytesWrittenSoFar;
assert(theConnection == self.connection);
dataLength = [data length];
dataBytes = [data bytes];
bytesWrittenSoFar = 0;
do {
bytesWritten = [self.fileStream write:&dataBytes[bytesWrittenSoFar] maxLength:dataLength - bytesWrittenSoFar];
assert(bytesWritten != 0);
if (bytesWritten == -1) {
[self _stopReceiveWithStatus:@"File write error"];
break;
} else {
bytesWrittenSoFar += bytesWritten;
}
} while (bytesWrittenSoFar != dataLength);
}
디버그 정보가 있습니까? 아, 그리고'assert (theConnection == self.connection)'은 여러개의 연결을 사용하면이 코드가 망가질 운명이됩니다. 'if (theConnection! = self.connection) {return;}을 사용하십시오. }'대신. –