在firebase中检索数据

时间:2017-04-27 14:58:16

标签: ios objective-c firebase

我是firebase和iOS的初学者。我正在尝试将项目从解析更改为firebase。我成功创建并更新了firebase数据库。但是在尝试从firebase中检索数据时,它只是不适合我。 这是我使用的代码。

self.ref = [[FIRDatabase database] reference];
NSString *userID = [FIRAuth auth].currentUser.uid;
[[[ref child:@"users"] child:userID] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
    NSLog(@"%@",snapshot.value);
    // Get user value
}withCancelBlock:^(NSError * _Nonnull error) {
    NSLog(@"%@", error.localizedDescription);
}];

控件刚刚跳过整个块。我无法弄清楚这个问题。 Firebase指南很难理解。请告诉我如何从firebase孩子那里获取字典值。

1 个答案:

答案 0 :(得分:0)

    DatabaseReference database = 
    FirebaseDatabase.getInstance().getReference();
    database.child("notes").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
    List notes = new ArrayList<>();
     for (DataSnapshot noteDataSnapshot : dataSnapshot.getChildren()) {
    Note note = noteDataSnapshot.getValue(Note.class);
    notes.add(note);
    }
   adapter.updateList(notes);
   }
   ...
   });