2017-04-11 91 views
0

我有titleFieldUITextView。如何在Firebase中实现PUT请求并将文本字段的数据发送给Firebase?Firebase中的PUT请求如何

+2

把你试过代码 – iOS

+0

的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] –

+1

@LipatovEugen请点击下面的[编辑](http://stackoverflow.com/posts/43343488/edit)链接将代码添加到您的问题中。 –

回答

0
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] 
0

这取决于你想放在哪里。 如果你有一个简单的结构,找到数据库单元的链接。 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"); 
                   }];