непосредственно взято из проекта:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
bytesCount = bytesCount + [data length];
[receivedData appendData:data];
//If the size is over 10MB, then write the current data object to a file and clear the data
if(receivedData.length > MAX_DATA_LENGHT){
[fileHandle truncateFileAtOffset:[fileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file
[fileHandle writeData:receivedData]; //actually write the data
[receivedData release];
receivedData = nil;
receivedData = [[NSMutableData data] retain];
}
[progressView setProgress:(float)bytesCount/sizeOfDownload];
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
DEBUG(@"Succeeded! Received %d bytes of data",[receivedData length]);
// Release and clean some ivars
//
[currentConnection release];
currentConnection = nil;
[fileHandle writeData:receivedData];
[receivedData release];
[fileHandle release];
..
, и это является частью процедуры начальной загрузки:
...
// create a path in doc's folder and initialize the file handler
NSString *temporaryZipPath = [self temporaryZipPathForResource];
NSMutableData *fake = [[NSMutableData alloc] initWithLength:0];
BOOL result = [[NSFileManager defaultManager] createFileAtPath:temporaryZipPath
contents:fake
attributes:nil];
[fake release];
if (!result) {
[super showAlertWithErrorDescription:@"Error creating file"];
return;
}
//
fileHandle = [[NSFileHandle fileHandleForWritingAtPath:temporaryZipPath] retain];
//
NSURLRequest *request = [NSURLRequest requestWithURL:[self audioPackageURL]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60.0f];
currentConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
receivedData = [[NSMutableData data] retain];
...
Надеюсь, это поможет.