【发布时间】:2017-01-19 13:07:36
【问题描述】:
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 和 FIRDataEventTypeChildChanged。
是我做错了什么还是 Firebase 中的错误?
【问题讨论】:
-
您的代码都没有触发任何更改,很难说您看到了什么。请提供minimal complete code that is needed to reproduce the problem。这将包括您正在阅读/修改位置的 JSON(作为文本,没有屏幕截图)、导致问题的侦听器代码以及更改值的代码。
-
弗兰克提供的答案很幸运地解决了我的问题顺便说一句感谢您的编辑,我会处理重现问题所需的最少代码。
标签: ios objective-c firebase firebase-realtime-database