从 firebase 数据库检索数据:代码没有进入完成块或错误块
Retrieving data from firebase database: code didn't go into the completion block or an error block
我正在尝试从数据库中检索数据,但我的代码没有进入完成块或错误块。我不希望用户进行任何身份验证并将数据从应用程序保存在数据库中。只想从数据库中检索数据。我的数据库结构是这样的
这是代码
- (void)viewDidLoad {
[FIRDatabase database].persistenceEnabled = YES;
[self referenceFromURL:@"https://project-8326407164650950213.firebaseio.com"];
}
- (FIRDatabaseReference *) referenceFromURL:(NSString *)databaseUrl{
commentsRef = [[FIRDatabase database] referenceFromURL:databaseUrl];
return commentsRef;
}
-(void)viewWillAppear:(BOOL)animated
{
[[commentsRef child:@"Hello"]
observeEventType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary * post = snapshot.value;
}withCancelBlock:^(NSError * error){
NSLog(@"%@",error.description);
}];
}
告诉我我在该代码中遗漏了什么。
NSString *strUrl = [NSString stringWithFormat:@"https://project-8326407164650950213.firebaseio.com"];
FIRDatabaseReference *ref = [[FIRDatabase database] referenceFromURL:strUrl];
[ref observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *post = snapshot.value;
NSLog(@"%@",post);
}];
- 这是您将从 Firebase 获取数据的代码。
- 你的代码唯一的问题是你写了“[commentsRef child:@"Hello"]”。使用直接 urlreference 获取数据。
我正在尝试从数据库中检索数据,但我的代码没有进入完成块或错误块。我不希望用户进行任何身份验证并将数据从应用程序保存在数据库中。只想从数据库中检索数据。我的数据库结构是这样的
这是代码
- (void)viewDidLoad {
[FIRDatabase database].persistenceEnabled = YES;
[self referenceFromURL:@"https://project-8326407164650950213.firebaseio.com"];
}
- (FIRDatabaseReference *) referenceFromURL:(NSString *)databaseUrl{
commentsRef = [[FIRDatabase database] referenceFromURL:databaseUrl];
return commentsRef;
}
-(void)viewWillAppear:(BOOL)animated
{
[[commentsRef child:@"Hello"]
observeEventType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary * post = snapshot.value;
}withCancelBlock:^(NSError * error){
NSLog(@"%@",error.description);
}];
}
告诉我我在该代码中遗漏了什么。
NSString *strUrl = [NSString stringWithFormat:@"https://project-8326407164650950213.firebaseio.com"];
FIRDatabaseReference *ref = [[FIRDatabase database] referenceFromURL:strUrl];
[ref observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *post = snapshot.value;
NSLog(@"%@",post);
}];
- 这是您将从 Firebase 获取数据的代码。
- 你的代码唯一的问题是你写了“[commentsRef child:@"Hello"]”。使用直接 urlreference 获取数据。