This是我通过Android应用程序将数据写入firebase的问题,我想在iPhone应用程序中以相同的方式表示信息。
我使用字典来表示键值对。
f = [[Firebase alloc] initWithUrl:@"https://ums-ios.firebaseio.com/"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"latitude",[[NSNumber numberWithFloat:latitude] stringValue],
@"longitude",[[NSNumber numberWithFloat:longitude] stringValue],
@"timestamp",[[NSNumber numberWithDouble:timeStamp] stringValue],
nil];
Firebase* tempRef = [f childByAppendingPath:@"mobileNum"];
[tempRef setValue:dictionary];
我尝试运行此操作时遇到异常。但是当我用NSDictionary
替换NSArray
时,我的数据已映射到array indices
,这不是我要求的。
有什么建议吗?
答案 0 :(得分:0)
我认为这是无关的,但你的字典是倒退的。我也发现它非常烦人,我觉得我总是需要仔细检查,但是值出现在iOS之前
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[[NSNumber numberWithFloat:latitude] stringValue], @"latitude",
[[NSNumber numberWithFloat:longitude] stringValue], @"longitude",
[[NSNumber numberWithDouble:timeStamp] stringValue], @"timestamp",
nil];
完整的代码就是这个
float latitude = 30.472;
float longitude = 42.467;
double timeStamp = NSTimeIntervalSince1970;
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[[NSNumber numberWithFloat:latitude] stringValue], @"latitude",
[[NSNumber numberWithFloat:longitude] stringValue], @"longitude",
[[NSNumber numberWithDouble:timeStamp] stringValue], @"timestamp",
nil];
Firebase * f = [[Firebase alloc]initWithUrl:@"https://ums-ios.firebaseio.com/"];
Firebase* tempRef = [f childByAppendingPath:@"mobileNum"];
[tempRef setValue:dictionary];
这将创建以下URL方案(添加.json以便您可以轻松查看)
https://ums-ios.firebaseio.com/mobileNum/.json =字典
https://ums-ios.firebaseio.com/mobileNum/latitude/.json =纬度值
https://ums-ios.firebaseio.com/mobileNum/longitude/.json =经度值
https://ums-ios.firebaseio.com/mobileNum/timestamp/.json =时间戳的值
关于安全的说明,
我刚将这些数据保存到您的firebase,请确保在发布之前更新安全性!