據火力地堡錯誤監聽器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
更新孩子同時觸發FIRDataEventTypeChildAdded
和FIRDataEventTypeChildChanged
FIRDataEventTypeChildAdded不應該被觸發。
我做錯了什麼或者它是Firebase中的錯誤?
無代碼被觸發任何變化,很難說,你所看到的。請提供[重現問題所需的最小完整代碼](http://stackoverflow.com/help/mcve)。這將包括您正在閱讀/修改的位置處的JSON(如文本,沒有截圖),導致問題的監聽器的代碼以及更改值的代碼。 –
弗蘭克提供的答案幸運地解決了我的問題順便說一句,感謝編輯我會照顧重現問題所需的最低限度的代碼。 –