views:

82

answers:

2

In my app, i download around 25mb+ data. During the download process if the user press the center button and app goes background what should be done so that the download continues once the app comes to foreground

+1  A: 

You have a little bit time to store and decide to do something when the app goes into the background. I think the best way is you cut your data off by some way.

If it is text data, it will be easy, just break into many smaller text files and remember what you downloaded.

If it contains lots of images and videos, save the last (may be index) of the image or video you downloaded.

Generally, try to break up your data to many smaller ones so that a break in one will not affect other parts and you can redownload that part.

vodkhang
when the user select the app and if the app come from background to foreground, i always find the same screen is displayed. In that case i assumed that the download operation will resume. am i correct ?. note: I have not tested in the iphone yet.
thndrkiss
No, the download operation will not resume. Your download connection is broken and you have to start it again by your code
vodkhang
i have a doubt. I just tried to download from my iphone 3gs mobile with 4.0.2 os. It is working without any handling. i did not do any handling to the back to fore or vice versa. Is this a expected behaviour ?
thndrkiss
The reason may be your download ends before user quits your app. Do you test by quit your app immediately after the download starts
vodkhang
No the content is around 25 mb and will definitely take around 10 mins via wi-fi. i went background after 2 mins. I guess phone call can be the only way where i can determine that the urlconnection goes off.
thndrkiss
+1  A: 

Check out the Executing Code in the Background section of the iOS Application Programming Guide, which says:

Any time before it is suspended, an application can call the beginBackgroundTaskWithExpirationHandler: method to ask the system for extra time to complete some long-running task in the background.

David Gelhar
I think that extra time is not enough in this case, because 25+ MB of data is so big
vodkhang
That's possible; I believe the extra time you get is limited to 10 minutes (in the current OS release). Breaking your data up into smaller pieces as vodkhang says is good advice. Still, if you do want to continue at least some downloading in the background, the beginBackgroundTaskWithExpirationHandler: thing is good to know: by calling that, you get to run for 10 minutes instead of 10 seconds after the user hits the home button.
David Gelhar
I didn't test the 10 minutes. That's good fact to know. Then, I think that it is possible, 25+ MB of data for 10 minutes is not so much
vodkhang