2017-01-18 35 views
0

据火力地堡FIRDataEventTypeChildAdded :This event is triggered once for each existing child and then again every time a new child is added to the specified path.错误监听器FIRDatabaseReference解雇

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而FIRDataEventTypeChildChanged应触发更新一个孩子,但在_followerReference更新孩子同时触发FIRDataEventTypeChildAddedFIRDataEventTypeChildChanged FIRDataEventTypeChildAdded不应该被触发。

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

+0

无代码被触发任何变化,很难说,你所看到的。请提供[重现问题所需的最小完整代码](http://stackoverflow.com/help/mcve)。这将包括您正在阅读/修改的位置处的JSON(如文本,没有截图),导致问题的监听器的代码以及更改值的代码。 –

+0

弗兰克提供的答案幸运地解决了我的问题顺便说一句,感谢编辑我会照顾重现问题所需的最低限度的代码。 –

回答

3

这不是一个错误,我遇到了同样的问题。 确保您不会调用此方法递归

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

+1

这种方法是每30秒调用一次NSTimer选择器。删除那固定我的问题谢谢。 –