我正在尝试下载文件[> 40MB]来自Web服务器的HTTP请求。为此,我使用了apple提供的SimpleURLConnection示例。在该示例中,他们只下载图像文件,因此我修改了代码以下载pdf文件并将其存储在应用程序的文档目录中。这可以很好地下载小文件,但如果我尝试下载大文件[> 40Mb],它只下载6.4MB的数据。请帮我解决这个问题,
谢谢,
供参考:
使用下载数据编写文件的代码
- (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);
}