firebase-ios-sdk
firebase-ios-sdk copied to clipboard
FR: Allow background uploads and downloads
- Firebase SDK version: 4.04
- Firebase Product: storage
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:
-
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.
-
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).