larrysanchez
larrysanchez

Reputation: 127

Using firebase offline with iOS

I am wondering if anyone has had this issue, or if in-fact this is not an issue at all but a way that firebase is meant to operate.

I am using FEventTypeChildChanged to monitor changes to my firebase within my iOS8 app. However if the app is not currently running, and a child is changed online at a different location, this event is not called when the app re-starts.

It works fine when the app is online.

I used firebase a few months ago and I was sure that this event was called when returning from offline, however it does not seem to be the case now.

The code I am using is straight from the firebase docs:

Firebase *postsRef = [[Firebase alloc] initWithUrl: @"https://*******.firebaseio.com/"];

[postsRef observeEventType:FEventTypeChildChanged withBlock:^(FDataSnapshot *snapshot) {
    NSLog(@"%@", snapshot.value);
} withCancelBlock:^(NSError *error) {
    NSLog(@"%@", error.description);
}];

And the json structure looks something like :

{
  "test" : {
    "A value" : "test value" <== I am modifying 'test value'
  }
}

Thanks for your help in advance

Upvotes: 0

Views: 369

Answers (1)

Michael Lehenbauer
Michael Lehenbauer

Reputation: 16309

An app will never get "child changed" events immediately after (re-)starting. Instead, Firebase will just give you the appropriate set of events to get you up-to-date with the current state of the data. On a fresh start of the app, this will just be a bunch of "child added" events for all of the children that currently exist.

After your app starts and you've gotten your initial "child added" events, then if one of those children change, Firebase will notify you with a "child changed" event. But, you'll only get a "child changed" event after previously getting a "child added" event.

Upvotes: 1

Related Questions