1

I'm writing an app that requires background downloading. I've configured my NSURLSession to be in the background Session Configuration.

Everything is working when the app is in foreground or even in background mode (home button), but as soon as I press the power button to force the phone into sleep mode. The NSURLSession delegate call:

- (void)URLSession:(NSURLSession *)session 
        task:(NSURLSessionTask *)task 
        didCompleteWithError:(NSError *)error

returns with a Error Domain=NSPOSIXErrorDomain Code=1 "The operation couldn’t be completed. Operation not permitted" and my download fails.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
maxf
  • 411
  • 4
  • 5
  • This seems more like a statement than a question. I believe what you are describing is expected behaviour. Not exactly the same use case, but this question might be of interest: http://stackoverflow.com/questions/20159471/ios-does-force-quitting-the-app-disables-background-upload-using-nsurlsession – gavdotnet Dec 31 '13 at 10:38
  • Thanks for the comment. I was questioning this behavior because it seems odd to me that background uploads no longer function once the phone is not actively being used (which to me would seem like a perfect time to actually execute background tasks). I found in another stackoverflow thread ( http://stackoverflow.com/questions/19184490/nsurlsession-background-download-resume-over-network-failure ) that this behavior is indeed whats being experienced by others as well but it doesn't help my cause. I guess my implied question is how would one get around this issue? – maxf Jan 02 '14 at 20:03
  • When I press the power button on my device (iPad 4th gen), my download continues but in the background. Same happens for me on simulator. Could your Wifi be turning off when entering sleep mode? In any case you need to handle Wifi dropouts by saving the resumeData and restarting when the network is available again. – gavdotnet Jan 02 '14 at 20:17

1 Answers1

0

You have forgotten the bg-download entitlements (see target -> capabilities)

Olof_t
  • 766
  • 9
  • 22