Downloading heavy data from server using separate thread
<p>We are building an iPhone app and we are having a problem with downloading in-app purchases in the background and I was wondering if anyone had a solution … </p>

<p>Our in-app purchases are quite big 35-40mb, each purchase consisting of 5 items each 7-8mb so the phone typically goes into standby or the user switches apps before the purchase is downloaded so it is essential the in-app purchases are downloaded in the background seamlessly.</p>

<p>When we download the purchase we have to download about 35-40mb from the server and simultaneously update the local sqlite database in the app. We have tested downloading the items in the foreground and its working fine and we have done some handling to keep the download process continuing in the background and the download is continuing and we can see it working in the debugger.</p>

<p>However we have the following issue …</p>

<p>User starts download
Download page on app shows that the app is downloading 
User leaves app or phone goes into standby
User returns to app</p>

<p>At this point the app splash screen loads and stays on the screen until one of the 8mb downloads has completed, when completed it then switches to the download page on the app. This is really confusing for the user as they think the app has crashed.</p>

<p>So how can we manage the in-app purchase so that when the user presses download it starts the download in the background and the app behaves as normal while the download is in progress? So user leaves app and when they return it shows the correct page with download progress. User navigates within app and it works fine.</p>

<p>Some observations ...</p>

<p>I have to run the NSURLConnection consecutively five times to perform downloading, because each in-app purchase has 5 items. </p>

<p>The thing I noticed is that when the first download is in progress the "didEnterBackground" method doesn't  get called even if the user presses the home button but after the 1st download process is completed then "didEnterBackground" method does get called. And if the user puts the app into the background and then returns to the foreground the "didEnterForeground" should be called but it isn't.</p>

<p>I am downloading data using a different thread then "MainThread" ,but still running in same issue.</p>

<p>Any help would be much appreciated.</p>
