Re: Background tasks completing without notification
Re: Background tasks completing without notification
- Subject: Re: Background tasks completing without notification
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 05 Mar 2014 09:43:04 +0000
On 4 Mar 2014, at 23:45, Scott Hancher <email@hidden> wrote:
> How can I check on the actual state of the upload task on relaunching my app?
It seems pretty clear that the background session has forgotten about your task. The reason why that's happened is less clear. The standard causes for tasks disappearing are:
A. the task was cancelled
B. the session was invalidated
You should add logging to your app to ensure that you're not doing either of these. Pay particular attention to B because I've seen various NSURLSession examples that are quite gung ho about invalidating sessions.
> How can I check on the actual state of the upload task on relaunching my app? I've added logic that assumes a failed upload if on re-launch getTasksWithCompletionHandler: returns 0 tasks and I don't get a callback to NSURLSession delegate within a short timeframe.
-getTasksWithCompletionHandler: should be all you need here. This method is obviously racy but you can be assured that any task that existed at the point when you called -getTasksWithCompletionHandler: is passed to the completion block when it's called. You just have to watch out for races with your own code (creating or cancelling tasks) and tasks completing (which you'll hear about via the delegate callback).
Can you reproduce this on the simulator? If so, there's stuff you can do to poke around in the persistent state of nsnetworkd.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden