![使用野狗(Wilddog)云setValue写入数据 使用野狗(Wilddog)云setValue写入数据](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
- (void)viewDidLoad {
[super viewDidLoad];
//创建野狗实例化对象 用于随时监听数值变化
Wilddog *myRootRef = [[Wilddog alloc] initWithUrl:@"https://exile.wilddogio.com/weather"];
//监听键值
[myRootRef observeEventType:WEventTypeValue withBlock:^(WDataSnapshot *snapshot) {
NSLog(@"%@ -> %@", snapshot.key, snapshot.value);
}];
//为weather键赋初始值
[myRootRef setValue:@"Sunny"]; UIButton* btn1=[[UIButton alloc]initWithFrame:CGRectMake(, , , )];
btn1.backgroundColor=[UIColor orangeColor];
[btn1 addTarget:self action:@selector(changeValue1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1]; UIButton* btn2=[[UIButton alloc]initWithFrame:CGRectMake(, , , )];
btn2.backgroundColor=[UIColor orangeColor];
[btn2 addTarget:self action:@selector(changeValue2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2];
} -(void)changeValue1
{
Wilddog *myRootRef = [[Wilddog alloc] initWithUrl:@"https://exile.wilddogio.com/weather"];
[myRootRef setValue:@"Snow"];
} -(void)changeValue2
{
Wilddog *myRootRef = [[Wilddog alloc] initWithUrl:@"https://exile.wilddogio.com/weather"];
[myRootRef setValue:@"Wind"];
}