据火力地堡错误监听器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(如文本,没有截图),导致问题的监听器的代码以及更改值的代码。 –
弗兰克提供的答案幸运地解决了我的问题顺便说一句,感谢编辑我会照顾重现问题所需的最低限度的代码。 –