Does anyone know whether remote calls to Firebase using Firebase iOS SDK use main thread or a background thread?
I couldn't find anything in documentation.
Firebase does not entirely eliminate the need to worry about threading. Because Firebase callbacks always return on the main thread, you need to be especially careful when calling Firebase observe/ observerSingleEvent from the background thread.
Consider the use case:
DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async {[weak weakSelf = self] in
// Do something computationally intensive
ref.child(somePath).observeSingleEvent(of: .value, with: { (snapshot) in
DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async {[weak weakSelf = self] in {
// Do some computationally intensive non-critical activity based on data retrieved from Firebase
}
}
}
Firebase uses it's own background thread. But as Jay mentioned in the comments, Firebase eliminates the need to worry about threading.
So essentially there's no need to run Firebase in your own background thread.
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