The best way to download large files from the Internet to iPhone for burning to disk

In the iPhone application, I have code to download a file from the Internet to the iPhone and save it to disk.

The problem is that if the file is large, then the memory usage in applications grows, and the application crashes.

I’m sure that I’m just not doing this “right.”

I currently have the following:

mediaData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:path]]; [mediaData writeToFile:fullPath atomically:YES]; [mediaData release]; 

As I said, this works for something like a picture, but not for something like a video, because the application crashes.

What is the correct way to do this so that my application does not crash? My thought was probably sockets, but since I did not program the socket much, I am not sure.

thanks

+1
source share
2 answers

You can use NSURLConnection , which runs asynchronously and delivers data to managed blocks.

+5
source

Since NSURLDownload not available on iPhone, you can use NSURLConnection and buffer some data in NSMutableData using the connection:didReceiveData: delegate method. This article describes the following: http://dannyg.com/iapps/Blog/Entries/2009/2/16_The_Joy_in_Discovering_You_Are_an_Idiot.html

+2
source

Source: https://habr.com/ru/post/1303422/


All Articles