I was facing some problem while downloading the large content:
Using the
Using the
NSURLConnection
class to download a large file in an iPhone application, but it crashes every so often because it’s using too much memory. I’m doing the usual NSURLConnection
usage, to append the received data to a NSMutableData
object.
Solution to the above problem is:
In the delegate method connectionDidReceiveData, we can store the content in the file
In the delegate method connectionDidReceiveData, we can store the content in the file
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
filename = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:save_name];
NSFileHandle *file1 = [NSFileHandle fileHandleForUpdatingAtPath: filename];
[file1 writeData: data]; [file1 closeFile];
}
No comments:
Post a Comment