0
votes

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?

1
I'm finding it very hard to get good information about what background tasks are doing. Have you looked at the device console log for clues? Sometimes error messages will show up there.Phillip Mills
Yes, I got this message from the device console, xCode debug prevents this crash from happening, so the only way I found to debug this is using NSLog and the device consoleLeonardo

1 Answers

1
votes

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