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
和{{1} }。
我做错了什么或者它是Firebase中的错误?
答案 0 :(得分:3)
这不是一个bug,我遇到了同样的问题。 确保你没有递归地调用这个方法
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType withBlock:(void (^)(FIRDataSnapshot *snapshot))block withCancelBlock:(nullable void (^)(NSError* error))cancelBlock;