0
votes

In my Firebase iOS app, I have an endpoint pointing to users in the app called "users", inside this endpoint, the basic structure is as follows:

The problem I faced now (it worked perfectly fine before) is that when I use observeEventType or observeSingleEvent and try to retrieve the snapshot.value in the path: "users/userid-#", it gives me null even though the data are shown on my dashboard at that location.

This case only happens for one of the userid's. I can successfully retrieve all other users' data. Since the data are actually shown on the dashboard, so I have no idea why when retrieving the data I got null instead of the data shown in that location.

The code I use is very simple:

Firebase *testRef = [self.ref childByAppendingPath:@"users/userid-1"];
[testRef observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)     {
    NSLog(@"%@", snapshot.value);
}];

What I got is null instead of the data

Anyone have any ideas on what might have happened?

Thanks!

3
Seeing the code that you use and the actual JSON (as text, which you can easily get by clicking the Export button in your Firebase dashboard) would go a long way here. See MCVE. - Frank van Puffelen
I edited with the basic code I use. Nothing fancy. - Carl Pan
Please read the page about providing an MCVE I linked. The JSON is still missing from your question, which means we have to make something up that might or might not reproduce the problem. The easier you make it for someone to help you, the more likely you are to get help. - Frank van Puffelen
What happens if you just grab all users and print them out in the console? It's likely something as simple as that you're using the wrong kind of dash symbol. - Cesar

3 Answers

0
votes

First of all make sure you are authenticated. If you want to let users search for that node without being authenticated please update rules read:true.

Update firebaseReference deprecated function childByAppendingPath with child function:

Firebase *testRef = [[self.ref child:@"users"] child:"userid-1"]; 
[testRef observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)     {
        NSLog(@"%@", snapshot.value); }];

this is it.

0
votes

For latest Firebase SDK

Create the firebase reference as:

@property (strong, nonatomic) FIRDatabaseReference *dataRef;

And call your observer as:

dataRef = [[dataRef child:@"users"]child:@"userid-1"];

[dataRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot){

     NSLog(@"%@", snapshot.value);

})

It worked for me.

-1
votes

Please check that you have appropirate node in the firebase database. as well as added some values over there.