Alfie Hanssen
Alfie Hanssen

Reputation: 17094

NSURLSession background tasks: when to call the handleEventsForBackgroundURLSession: completionHandler?

I'm using an NSURLSession to upload multiple video files.

The application:handleEventsForBackgroundURLSession:completionHandler: method is called several times, seemingly after each task completes. I store the completionHandler that's passed to this method so that I can invoke it later.

My question is this: do I invoke it each time the above application delegate method is called? Or do I invoke it only when my background session's [tasks count] == 0? When I do the latter the app crashes in the background with this info in the console:

Application Specific Information:
<BKNewProcess: 0x134d48400; com.vimeo; pid: 2141; hostpid: -1> has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x134d49500> id: 1679-3230372B-D4E5-44A1-A8DD-221CA8E6EECE name: com.apple.nsurlsessiond.handlesession com.vimeo.app.BackgroundSessionIdentifier process: <BKNewProcess: 0x134d48400; com.vimeo; pid: 2141; hostpid: -1> permittedBackgroundDuration: 30.000000 reason: backgroundDownload owner pid:1679 preventSuspend  preventThrottleDownUI  preventIdleSleep  preventSuspendOnSleep 
)}

I have read many StackOverflow and blog posts on background sessions and their intricacies, and I see conflicting information regarding the above question.

Thanks in advance for any help.

Upvotes: 0

Views: 994

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31016

The docs for URLSessionDidFinishEventsForBackgroundURLSession say to call it there. I've been doing that just because they said to and I haven't seen any related problems.

Upvotes: 1

Related Questions