When I send a synchronous request with NSURLConncetion
[NSURLConnection initWithRequest:myRequest delegate:self];
I can receive my downloaded data in pieces with the following method
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.videoData appendData:data];
NSLog(@"APPENDING DATA %@",data);
}
The advantage of this is that I can write my data directly to a file, and limit ram usage when downloading large files.
When I send an asynchronous request, how can I receive my data in pieces? The only place I see the data given back to me is in the completion handler of the request.
[NSURLConnection sendAsynchronousRequest:videoRequest
queue:downloadQueue
completionHandler:^(NSURLResponse* response, NSData* data, NSError* error){
NSLog(@"All data is given here!");
}];
Is there any solution to this problem? I'm downloading large files in a view controller and want to continue downloading them if the view controller gets dismissed. The problem is that I'm going to use too much memory if I receive all my data at once when downloading large files.