3lvis / Networking

Swift HTTP Networking with stubbing and caching support
MIT License
1.36k stars 112 forks source link

Using Networking lib to make a post in the background? #263

Closed ManjitBedi closed 3 years ago

ManjitBedi commented 3 years ago

Hello, I am currently trying out the library.

On the project, I am working on we have a need to do uploads of images in the background. I have the code working using a form post with the image data.

However, if I set the configuration to background, e.g:

let networking = Networking(baseURL: urlString, configuration: .background(withIdentifier: "com.appname"))

The app will throw an exception at run-time because of the completion block, as completion blocks are not permitted with background tasks:

networking.post(Api.backlogSync.rawValue, parts: parts) { result in

Do I need to create a new post method without a completion block? Or can you recommend another approach?

3lvis commented 3 years ago

Hi @ManjitBedi,

That's one of the missing features in Networking, doesn't handle background uploads as it should. I tried to make it work but it's been a while since I tried.

ManjitBedi commented 3 years ago

Thanks for the reply.

I see; yes, it is a bit of work to do support background uploads; I am currently doing my own implementation specific to the application that I am working on.

3lvis commented 3 years ago

That should work well! Take care :)