我在做两个查询吗?

Am I making two queries?

由于 PFFiles 只能通过 getDataInBackgroundWithBlock 检索,因为它们不是对象(我认为..)在进行查询后我调用 getDataInBackgroundWithBlock 将 PFFile 转换为 UIImage。

我是否通过调用 findObjectInBackgroundWithBlock 然后调用 getDataBackgroundWithBlock 进行了两次查询?如果是这样,是否有一种方法可以仅通过一个查询来完成此操作?

PFQuery *query = [PFQuery queryWithClassName:@"photoObject"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){

        for (id object in objects) {


            PFFile *imageFile = object[@"photo"];
            [imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
                if (!error) {

                    [self.annotationArray addObject:object[@"location"]];
                    NSLog(@"Annotation's coordinate : %@", self.annotationArray);


                    self.callOutImage = [UIImage imageWithData:imageData];

                    self.geoPoint = object[@"location"];

                    CLLocationCoordinate2D locCoord = CLLocationCoordinate2DMake(self.geoPoint.latitude, self.geoPoint.longitude);
                    CustomPin *pin = [[CustomPin alloc] initWithTitle:[object objectId] location:locCoord image:self.callOutImage];
                    [self.mainMap addAnnotation:pin];

                }}];

        }

    }];

您正在发出两个异步网络请求,但只有其中一个请求 -- findObjects -- 是一个查询。查找 returns 一个指向文件的对象,为了获取文件的内容,需要第二个(非查询)请求。

有一种方法可以通过来自客户端的单个请求完成您正在做的事情:一个云函数,其功能与发布的代码基本相同,然后 returns 检索到的数据。