I'd like to implement a file upload queue for my app. Files will be uploaded to Firebase Storage. I am able to upload the files using background thread while app is in foreground mode, my challenge is to continue the upload while the app is in background state. From my research so far, using NSURLSession an app can fetch data from the network but I am not sure how to use this with Firebase API.
Thanks in advance.
Question was asked ~6months ago but I was trying to solve the same problem so stumbled upon it. If it helps, I was able to solve this by setting up the standard iOS background task:
backgroundUploadID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
Did this before the call to:
uploadTask = firebaseStorageRef.put(data!, metadata: metadata)
All the upload observers - .progress, .success & .failure - are called when the app is in the background. In case of '.success', 'failure' call:
UIApplication.shared.endBackgroundTask(currentBackgroundUploadID)
I assume that if my uploads were huge, the OS would have cut me off at some point. I'm uploading iPhone camera photos ~3mb each.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With