0

If I have a valid key in firebase the code returns a "1", if I delete the key the code should return "0", because the snapshot does not exists anymore. But that only happens if I set persistenceEnabled = NO. If it is YES, the first time observeSingleEventOfType returns the old value "1" which does not exists! After a second call of observeSingleEventOfType the correct value of "0" is returned. So it seems to me that if persistenceEnabled is YES, the value is always returned from disk first before getting the value from firebase.

- (void)viewDidLoad {
    [super viewDidLoad];
    [Firebase defaultConfig].persistenceEnabled = YES;
}

- (void)getSeenCounter {
    Firebase *userRef = [Firebase userRef: @"keyname"];
    [userRef removeAllObservers];
    [userRef observeSingleEventOfType: FEventTypeValue withBlock: ^(FDataSnapshot *snapshot) {
        if (snapshot.exists) {
            //Value returned is 1
        } else {
            //Show a value of 0
        }
    }];
}


- (IBAction)showSeens:(id)sender {
    [self getSeenCounter];
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user1894278
  • 86
  • 1
  • 7
  • "if persistenceEnabled is YES, the value is always returned from disk first before getting the value from firebase" That is indeed the current behavior. I recommend using either `persistenceEnabled` or `observeSingleEventOfType`, but not both. I wrote a few answers on this before, e.g. http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent – Frank van Puffelen Apr 14 '16 at 14:50
  • Hi Frank, that's what I thought is happening. Thanks for your answer. – user1894278 Apr 15 '16 at 14:06

0 Answers0