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];
}