Why network request is getting killed after going to backgound and how to continue a network request in background?

Hello, I have asked some difficult questions here, and got no valid response. So , right now I should really get some real help. The problem is that I am creating network request which uploads 6 photos. As soon as I startNetwork request I open anotherViewController and go to background and return, my request is killed and I am getting an error, that connection is interrupted. I learned about background task and this is what I have created:
let config = URLSessionConfiguration.background(withIdentifier: "test") let session = URLSession(configuration: config) let upload = session.uploadTask(with: URLRequest(), from: Data()) { (data, response, error) in // Completion }

Still I have removed all closures and I am getting an exception:

Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘Completion handler blocks are not supported in background sessions. Use a delegate instead.’

How can I make sure that if user started uploading photos, goes to background and returns, that request is not killed and will continue???
I have read all articles, no information in website… If there are better ways to do that, please share.

I am doing this in framework, so I don’t have device requirements in target project

@wellbranding Do you still have this issue?

@shogunkaramazov yes. I tried other methods, and eventually I found that you can’t use Post requests as background tasks. You can only use it for file uploading. However, I don’t know how can I convert our POST request to become like a file uploading.

This part is still a closure being used as a completion handler block, even if it is just a comment. Did you try using a delegate instead?

This topic was automatically closed after 166 days. New replies are no longer allowed.