Pergunta

NSURLSession seems like a great new API. Sadly, documentation is still lacking.

I am planning on supporting NSURLSession background modes. I read that, these tasks will only download on the Apple daemon if the user is connected over Wifi, and if he has sufficient battery remaining. So if I queue some tasks, and the aforementioned conditions are not met, the task will await until they are. But what happens if the user opens the application and the data is missing? Will the pending tasks execute despite lack of wifi or low battery? Should I be cancelling them and starting them as data tasks in-process? I am aware of the discretionary property, but would tasks scheduled in the background start once the app is launched/resumed?

Foi útil?

Solução

You will either be resuming from background, or starting new again.

If resuming from background, the background NSURLSession should complete the tasks you queued, so long as you "retain/retained" it. My experience is background sessions work just fine in foreground, they are just limited (e.g. no data tasks).

If starting anew, you can "rewire" your background session by using the same configuration NSString you used, e.g.

NSURLSessionConfiguration config = 
 [NSURLSessionConfiguration backgroundSessionConfiguration:sameStringHere];

Once "rewired", it should keep rolling.

Agreed about the docs.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top