Firebase FIRStorageUploadTask On Swift while app is in Background state

送分小仙女□ 提交于 2020-01-14 12:45:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/39273893/firebase-firstorageuploadtask-on-swift-while-app-is-in-background-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!