Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase withCompletionBlock not called if there is no connection

Tags:

ios

firebase

I am using the following:

Firebase *fb =[[Firebase alloc] initWithUrl:url];
            [fb setValue:d withCompletionBlock:^(NSError *error, Firebase *ref) {
                if (error) {
                    // bad news
                } else {

                }
            }];

This seems to work great IF you have a connection, if not it seems the callback is never called. If that is the case do I then need to wrap this whole thing in a connectedRef? Seems like alot of extra work when I would guess the completion block would just fail with an error status of not online.

Anyone else having this issue?

like image 223
Slee Avatar asked Dec 08 '13 12:12

Slee


1 Answers

The idea behind Firebase is it synchronizes data for you. It's more than just a simple request / response system. So if you do a setValue while offline, Firebase will hold onto that data until you are online, and then it'll do the setValue at that time (and then the completion block will be called).

So the behavior you're seeing is expected. If you only want to do the setValue if you're online, then yes, you'll need to use a .info/connected observer. But you could still run into issues if for instance you go offline at the moment you try to do the setValue or something along those lines. In general it's better to just do the setValue and let Firebase take care of it for you.

like image 58
Michael Lehenbauer Avatar answered Oct 16 '22 05:10

Michael Lehenbauer