Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从firebase数据库检索数据:代码为';不要进入完成块或错误块_Ios_Objective C_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios 从firebase数据库检索数据:代码为';不要进入完成块或错误块

Ios 从firebase数据库检索数据:代码为';不要进入完成块或错误块,ios,objective-c,firebase,firebase-realtime-database,Ios,Objective C,Firebase,Firebase Realtime Database,我试图从数据库中检索数据,但我的代码没有进入完成块或错误块。我不想从用户那里获得任何身份验证,也不想从应用程序将数据保存到数据库中。只是想从数据库中检索数据。我的数据库结构是这样的 这是密码 - (void)viewDidLoad { [FIRDatabase database].persistenceEnabled = YES; [self referenceFromURL:@"https://project-8326407164650950213.firebaseio.co

我试图从数据库中检索数据,但我的代码没有进入完成块或错误块。我不想从用户那里获得任何身份验证,也不想从应用程序将数据保存到数据库中。只是想从数据库中检索数据。我的数据库结构是这样的

这是密码

- (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”]”。使用直接URL引用获取数据

我没有在这里使用错误块。