2017-01-18 53 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選擇器。刪除那固定我的問題謝謝。 –