Open tonysung opened 7 years 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
Is there any progress on the original aim here please (ie. adding background support)?
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.
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).