0

I have an NSURLSessionUploadTask running in background session. It is a POST with a small data and receives a large response from server. It works fine when the app is in foreground. However, as soon as I put the app in background, I get a call to the delegate with an error NSURLErrorDomain, error code: -997 "Lost connection to background service".

I have seen this error referenced in other posts in the context of a download task.

Has anyone seen this error with an upload task?

Does the fact that the upload body is much smaller than the response body have anything to do with this behavior?

sixthcent
  • 1,150
  • 7
  • 6
  • 1
    removed the tag NSURLSessionDataTask – sixthcent May 07 '15 at 21:43
  • Good, because that's one source of this error. Since the `POST` is so much smaller than the response, have you considered download task? Seems like a more logical alternative. Does that manifest the same behavior? – Rob May 07 '15 at 21:59
  • Good suggestion. I will try to use it as NSURLSessionDownloadTask. Does the download task support POST with a body? – sixthcent May 07 '15 at 22:13
  • Yes, you can have download tasks with `POST` and a body. Just create `NSMutableURLRequest` and set the `HTTPBody`. – Rob May 08 '15 at 03:40
  • Interesting, when I tried to use download task, I get an error "URL not available on the server". Does it expect a "Content-Disposition" header in the response by any chance? – sixthcent May 09 '15 at 14:20
  • No. I just used [Charles](http://charlesproxy.com) to watch my `POST`-based download task requests running on background session and `Content-Disposition` is not one of my resulting response headers. I'd suggest you use Charles (or something like it) to compare the upload tasks against the download tasks and make sure there isn't something wrong in the creation of the download tasks. – Rob May 09 '15 at 15:00

0 Answers0