firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.67k stars 1.49k forks source link

FR: Allow background uploads and downloads #147

Open tonysung opened 7 years ago

tonysung commented 7 years ago

When an UploadTask/DownloadTask is created when the app is in background, it does leverage NSURLSession's background transfer and "discretionary" is set to true by default by the OS:

https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1411552-discretionary

The result is that the task will be performed at the OS's discretion, like only if the device is WiFi connected.

However, the current API is limited in two aspect:

  1. Sometimes an app would like the task to proceed in background no matter what (with "discretionary" set to false). There's no way in Firebase API to specify this.

  2. Usually an app would create the UploadTask/DownloadTask when it is running in foreground, but expect the task to continue running in background and at the OS's discretion (i.e. NSURLSession created with [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier] and with "discretionary" set to true). This is useful for performing large files transfer without requiring the user to keep the app opened and simultaneously give discretion to the OS to help avoid consuming precious cellular bandwidth.

Hence, it'll be best if Firebase iOS can provide explicit API for an app to specify if OS discretion is allowed in an UploadTask/DownloadTask, and that the task can be run in background (even if the task is created when the app is in foreground).

xaphod commented 1 year ago

hi @paulb777 thank you for taking the time to look into this. I've just tried again to repro and I can't reproduce it anymore. I'm not sure if something changed between GTMSessionFetcher 2.x -> 3.x but in any case I apologize, I should have tried the repro again before my last post. I will keep an eye on this and see if I can get a repro again

maxbeech commented 1 year ago

Is there any progress on the original aim here please (ie. adding background support)?

anton-plebanovich commented 3 months ago

I had an issue with file upload in the background. After spending some time with source code investigation I have found a solution. Background session is not created when putData is used instead of putFile so I switched to that and solved my problem.