Reputation: 1655
I want to download a large video file to Iphone in my app. I used NSURLConnection and saving the file to disk once it completly downloads the video.
As my video is large, it is crashing in middle.
Is there anyway like directly saving the file to disk without keeping it in memory.
Thanks,
Upvotes: 1
Views: 883
Reputation: 1320
Your app crashes because you can't have this much data into your system's memory.
I recently wrote a little and very easy library to do that. It uses NSURLConnection
and won't cause your app to crash because the data is directly written to a file while downloading. Also, you can download multiple files at once and many other things...
You can have it here!
Upvotes: 0
Reputation: 28874
NSURLConnection
calls a method you can write called
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
which receives the data in smaller chunks. You can save that data to a file as you receive it.
Here is Apple's doc on NSURLConnection
, which gives more details.
Also note that you risk app-store rejection if you're retrieving a large amount of data via Edge or 3G, although using wireless is safe: app rejected reason.
Upvotes: 2