使用Nest API,我正在尝试设置nest恒温器的离开状态
我能正确地读出状态。对这个API有一定经验的人知道如何处理setting这种状态吗?
在"FirebaseManager.h"中
Firebase *newFirebase2 = [self.rootFirebase childByAppendingPath:@"structures"];
[newFirebase2 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
// Put structures into a dictionary
NSMutableDictionary *dict = snapshot.value;
NSLog(@"\n\n\n1. Away Status = %@", [dict valueForKey:@"away"]);
NSLog(@"Dict Contents %@", dict); // <--- Reads thermostat status. A string either home or away
dict[@"away"] = @"away"; //<--- Changes status string but not a correct solution, and does not set the stat to away
//Changes status name but this is not parsed back to firebase
NSLog(@"new status = %@", [dict valueForKey:@"away"]);
}];发布于 2016-03-22 19:45:13
更新子值
假设这个结构
structures
structure_id_0
away: "home"将离开节点设置为一个离开字符串(这段代码非常冗长,因此很容易理解)
Firebase *structuresRef = [self.rootFirebase childByAppendingPath:@"structures"];
//build a reference to where we want to write structures/structure_id/
Firebase *thisStructureRef = [structuresRef childByAppendingPath:@"structure_id_0"];
Firebase *awayRef = [thisStructureRef childByAppendingPath:@"away"];
[awayRef setValue:@"away"];现在,如果您想对通过使用FEventTypeChildAdded观察节点而检索到的快照执行此操作,则节点名将是替代structure_id_0的任何名称。是键的键:值对。
这可以通过snapshot.key获得。
所以NSString *key = snapshot.key
将路径中的键变量替换为@structure_id_0。
还可以查看[消]火基写入数据,然后查看另一个选项的updateChildValues。
https://stackoverflow.com/questions/36162283
复制相似问题