0
我有titleField
和UITextView
。如何在Firebase中實現PUT請求並將文本字段的數據發送給Firebase?Firebase中的PUT請求如何
我有titleField
和UITextView
。如何在Firebase中實現PUT請求並將文本字段的數據發送給Firebase?Firebase中的PUT請求如何
NSDate * now = [NSDate date]; NSDictionary *post = @{@"sender": target text filed (self.textfield.text), @"message": self.textView.text, @"time": [NSDateFormatter localizedStringFromDate:now dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle], }; NSDictionary *childUpdates = @{@"your storage link goes here/message.json": post}; [_ref updateChildValues:childUpdates]
這取決於你想放在哪裏。 如果你有一個簡單的結構,找到數據庫單元的鏈接。 https://YOUR_DATABASE_REF.firebaseio.com/CHILD/CHILD_OF_CHILD/
FIRDatabaseReference *reference = YOUR_REF;
NSDictionary *values = [NSDictionary dictionaryWithObjectsAndKeys:
self.textField.text,SOME_NAME"KEY", nil];
[reference updateChildValues:values withCompletionBlock:^(NSError *__nullable err, FIRDatabaseReference * ref){
if(err) {
NSLog(@"Error save");
return;
}
NSLog(@"Saved seccessfully in FireBace db");
}];
把你試過代碼 – iOS
的NSDate *現在= [NSDate的日期] 「NSDateFormatter localizedStringFromDate:now dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle],} NSDictionary * post = @ {@」sender「:self.titleField.text, @」message「:self.textView.text, @」time「 ; NSDictionary * childUpdates = @ {@「https://nasheradio-eda64.firebaseio.com/message.json」:post}; [_ref updateChildValues:childUpdates] –
@LipatovEugen請點擊下面的[編輯](http://stackoverflow.com/posts/43343488/edit)鏈接將代碼添加到您的問題中。 –