¿Cómo debe usarse beginBackgroundTaskWithExpirationHandler: para la continuación de las tareas existentes?

All the examples of use and tutorials I have found on beginBackgroundTaskWithExpirationHandler: show how to wrap a Un nuevo task or tasks into a block for execution.

However if an activity has already started, for example suppose NSURLConnection is in the middle of a download, when the app goes into the background. Then how can that activity be dealt with using beginBackgroundTaskWithExpirationHandler?

Muchas Gracias

preguntado el 31 de enero de 12 a las 16:01

1 Respuestas

You should just wrap it in the background task block anyway. Then if the app enters the background, you will be allowed to continue.

Respondido el 31 de enero de 12 a las 21:01

I'm not clear on how a complex series of interactions between different classes should be made background capable - for example suppose a model manager class uses a downloader class to download files, then when it receives notification that's complete it saves the files, then uses a parser class to parse the files, then looks at a queue to see if there's anything else to download and if so uses the downloader class again ... and so on. Every example I've seen of wrapping tasks for beginBackgroundTaskWithExpirationHandler are simple and not real-world examples. - Gruntcakes

@Woofbeans: I am on the same boat on this. see if someone can shred light on this. - user523234

Another point you should bear in mind that even with this facility, you have only about 10 min to complete the tasks after getting pushed to the background. So your app should be prepared for getting suspended at any stage of processing . Maintain some sort of a state machine to track what stage of processing you were in and pick up from there (or redo an interrupted task) when you get back to the foreground. - rajagp

Thanks, yes I know that. My next question would be - anybody know of good sources of examples of i.e. maintaining a state machine in conjunction with blocks/beginBackGroundTaskWithExpirationHandler? All the examples in the books are fine for introducing the concepts, but are totally useless for knowing how to apply to more complex scenarios. - Gruntcakes

I'll put this down as something to write a post about at some point. - Ell Neal

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.