Firebase更新子项是iOS更新中的updateChildValues,不删除旧值但在Web和Android中删除旧数据并添加。看起来firebase方面的一个bug不确定。
iOS代码
self.viewFirebase = [[Firebase alloc] initWithUrl: [NSString stringWithFormat:@"%@messages/%@",fOrgURL,self.userHash]];
Firebase *insertData = [self.viewFirebase childByAutoId];
Firebase *notificationRef = [[Firebase alloc] initWithUrl: [NSString stringWithFormat:@"%@notifications/%@/%@/",fOrgURL,fromHash,self.userHash]];
NSDictionary *dummyData = @{@"a":@"0"};
NSDictionary *messageIDDict = @{insertData.key : dummyData};
Firebase *lastData = [notificationRef childByAppendingPath:@"inbox/"];
NSDictionary *lastSentData = @{@"msgs":messageIDDict,@"sender": toHash,@"lastSender":[[AuthDataStore sharedAuth] pushKey], @"text" : messageInput, @"ack":@"ok", @"time":[NSNumber numberWithInt:timeStamp]};
[lastData updateChildValues:lastSentData];
Android代码
//Note: receiverinbox and notificationMsgs are hashmaps;
Firebase mNotificationref=new Firebase(FIREBASE_URL+"/notifications");
receiverinbox.put("sender",userid);
receiverinbox.put("text", input));
receiverinbox.put("time", Utilities.getCurrentTime());
receiverinbox.put("ack","no");
notificationMsgs.put(messagepush,placeholder); // messagepush is firebase pushid, placeholder is not null
receiverinbox.put("msgs",notificationMsgs);
mNotificationref.child(chatwithid).child(userhash).child("inbox").updateChildren(receiverinbox);
Angular JS
var msgsVal = {};
msgsval[msgId] = {placeholder : 1}; // MsgID is firebase pushkey
var rcvrNotificationConvRef = new Firebase(sessionURL + '/notifications/' + $scope.ustoId + '/' + msgkey);
rcvrNotificationConvRef.child('inbox').update({
sender: sender,
time: time,
text: msgintext,
ack: 'No',
lastSender: $scope.usLoggedUserId,
msgs : msgsVal
});
答案 0 :(得分:0)
在Android中,我们可以使用push()
方法将数据附加到多用户应用程序中的列表中。每次将新子项添加到指定的Firebase参考时,push() method都会生成唯一键。