Leonardo
Leonardo

Reputation: 1750

NSURLSession: background crash because upload delegates aren't called

I have been trying to use the background upload of NSURLSession, but occasionally I get this crash

Sep 25 10:01:48 ipad backboardd[29] <Warning>: MyApp[11829] has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x166b1770> identifier: com.apple.nsnetworkd.handlesession process: MyApp[11829] permittedBackgroundDuration: 30.000000 reason: backgroundDownload owner pid:8440 preventSuspend  preventThrottleDownUI  preventIdleSleep  preventSuspendOnSleep 
)}

Debugging the code, I figured out that when the crash happens, the application: handleEventsForBackgroundURLSession:completionHandler: method is called, where I recreate the session and store the completion handler like Apple Documentation reccomends, but the delegates of the task end are never called, and neither is URLSessionDidFinishEventsForBackgroundURLSession:, which explains the crash, because I call the completion handler after I processed the end of the upload in a NSURLSession delegate.

Can anyone tell me why the delegates aren't called?

Upvotes: 0

Views: 1514

Answers (1)

Leonardo
Leonardo

Reputation: 1750

I figured out the problem, a bug in my code caused me to call the completion handler twice sometimes. The next time the app was woken up, the delegates were never called, so the completion handler wasn't called either, which caused the crash

Upvotes: 1

Related Questions