【发布时间】:2016-09-23 10:23:29
【问题描述】:
我正在尝试从 firebase 检索数据并尝试了不同的解决方案,但快照值返回 null。数据由“childbyAutoID”创建,我想使用当前 uid 检索它。
以下是三种解决方案,我试过了
解决方案 1:
NSString *ID = [FIRAuth auth].currentUser.uid;
[[[self.databaseRef child:@"User-Subscription"] child:ID] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *childData = snapshot.value;
NSLog(@"%@",childData); //Returns null
// ...
} withCancelBlock:^(NSError * _Nonnull error) {
NSLog(@"%@", error.localizedDescription);
}];
解决方案 2:
NSString *ID = [FIRAuth auth].currentUser.uid; //User ID
[[[self.databaseRef child:@"User-Subscription"] childByAutoId] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *childData = snapshot.value;
NSLog(@"%@",childData); //Return null
// ...
} withCancelBlock:^(NSError * _Nonnull error) {
NSLog(@"%@", error.localizedDescription);
}];
解决方案 3:
NSString *ID = [FIRAuth auth].currentUser.uid; //User ID
[[[[self.databaseRef child:@"User-Subscription"] childByAutoId] queryEqualToValue:ID]observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *childData = snapshot.value;
NSLog(@"%@",childData); //Return null
// ...
} withCancelBlock:^(NSError * _Nonnull error) {
NSLog(@"%@", error.localizedDescription);
}];
非常感谢您指出错误的任何帮助。谢谢。
【问题讨论】:
标签: objective-c xcode firebase firebase-realtime-database