已触发FIRDatabaseReference的错误侦听器

时间:2017-01-18 08:13:32

标签: ios objective-c firebase firebase-realtime-database

根据Firebase FIRDataEventTypeChildAdded :This event is triggered once for each existing child and then again every time a new child is added to the specified path.

的文档

FIRDataEventTypeChildAdded :This event is triggered once for each existing child and then again every time a new child is added to the specified path.

但是当我使用方法updateChildValues

更新指定节点的子节点时,它甚至被触发

updateChildValues Documentation

我的代码:

[_followersReference observeEventType:FIRDataEventTypeChildAdded
                            withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
                               //increment the badge here
                                //add in local DB
                                //can fire a local notification
                                RCFollowerFireBaseModel *remoteFollower = [RCFollowerFireBaseModel parseDictionary:snapshot.value];
                                GMSMarker *marker = [GMSMarker markerWithPosition:remoteFollower.location.coordinate];
                                marker.title = remoteFollower.name;
                                marker.snippet = remoteFollower.time;
                                marker.appearAnimation = kGMSMarkerAnimationPop;
                                marker.map = self.mapView;

                            }
                      withCancelBlock:^(NSError * _Nonnull error) {

                      }];

[_followersReference observeEventType:FIRDataEventTypeChildRemoved
                            withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
                               //decrement the badge here
                                //remove followers

                                NSLog(@"%@",snapshot);
                            }
                      withCancelBlock:^(NSError * _Nonnull error) {

                      }];


[_followersReference observeEventType:FIRDataEventTypeChildChanged
                            withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
                                //update the marker with the updated coordinates here
                                //can apply 
                            }
                      withCancelBlock:^(NSError * _Nonnull error) {

                      }];

我的问题是当我在_followerReference更新孩子时不应该触发FIRDataEventTypeChildAdded而应该触发FIRDataEventTypeChildChanged但是_followerReference更新孩子会触发FIRDataEventTypeChildAdded和{{1} }。

我做错了什么或者它是Firebase中的错误?

1 个答案:

答案 0 :(得分:3)

这不是一个bug,我遇到了同样的问题。 确保你没有递归地调用这个方法

- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType withBlock:(void (^)(FIRDataSnapshot *snapshot))block withCancelBlock:(nullable void (^)(NSError* error))cancelBlock;