Question

In my application, i've to download videos around 10 to my application and play accordingly. Each video is around 50 MB.
I'm using following code and then after downloading the video, i'm saving it to Application support folder to avoid icloud sync. But the problem is that when downloading the videos its crashing.

   [NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init]  completionHandler:^(NSURLResponse *response, NSData *rcvdDat, NSError * err) 
     {
      .
      .
      .
     }

What I'm thinking is that, while downloading the video, it resides in memory and so the total memory occupying by the app is increasing. Finally iOS is making the app to close. I would like to download the video and when ever a stream of data received, write to temp file and when completes move it to application support folder. Can some one help me on how to write it to file and save it at the end?
I cannot use 3rd party libraries (unless its small) due to legal issues.

Was it helpful?

Solution

The solution that I am suggesting is, dont use "sendAsynchronousRequest", instead use the NSURLConnection's delegate methods like didReceiveResponse, didReceiveData etc. When ever data is received, write(or append) it to a file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top