user2884707bond user2884707bond - 3 months ago 20
iOS Question

Does iOS Firebase framework downloads the file on different queue?

I have an app where I send a request to Firebase to download file from it's database.

Here is the code snippet!

// Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in
if (error != nil) {
// Uh-oh, an error occurred!
} else {
// Data for "images/island.jpg" is returned
// ... imageView.image = UIImage(data: data!)
}
}


So does Firebase sends the downloading operation in other queue other than MAIN queue? The reason why I have question is because I want to update my imageView.image so it would appear on the screen. I do know iOS framework requires MAIN queue to update the UI, so I want to make sure if I need to update it on main queue!

Answer

Firebase Storage does the download on a separate background queue so as to not block UI, but surfaces the callback on the main queue, which allows you to perform UI work immediately.

If you want to change which queue the callback is surfaced on, you can use the FIRStorage.setCallbackQueue() method (docs).

Comments