Reputation: 1155
History:
I am working on a project for which we need to support:
NSURLSession
. Content-Type: multipart/form-data
NSURLConnection
with bound pair of Streams as depicted in this Apple Sample.NSURLSession(Background Session)
by using uploadTaskWithStreamedRequest
:.Problem: Everything works if app stays in foreground, but if during upload I press the home key, the upload fails after some time with error:
Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service"
Also a little before the upload fails the Write/Producer Stream's NSStreamEventEndEncountered
is encountered.
Note: I know the work-around where I can write whole HTTP Post body to a temp file and use NSURLSession's
file upload API instead. But above is more appropriate if I can make it work.
Question: Can anyone guess what could be possible reason for the upload getting failed?
Sample Code: I have uploaded the iOS Sample Code + PHP Server Code to drop box. Here is the CODE
Thanks!
Upvotes: 0
Views: 1030
Reputation: 2012
You can't upload streamed tasks using Background Configuration. I successfully upload data only in two cases:
Upvotes: 1