如何在Firebase中更新生成的子记录?我收到以下关于特殊字符的错误,有没有办法生成没有特殊字符的子自动ID?
这是子自动ID的外观:-JmJFEe-Kq4BLLNfR0Ta
我的代码:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *myString = [prefs stringForKey:@"refString"];
A0SimpleKeychain *keychain = [[Application sharedInstance] store];
A0UserProfile *profile = [NSKeyedUnarchiver unarchiveObjectWithData:[keychain dataForKey:@"profile"]];
// Create a reference to a Firebase location
NSString *theUrl = [NSString stringWithFormat:@"https://firebaseUrlGoesHere/%@",profile.nickname];
// Create a reference to a Firebase location
Firebase *ref = [[Firebase alloc] initWithUrl:theUrl];
// Write data to Firebase
NSDictionary *feedItems = @{
@"description" : description.text,
@"url": url.text,
@"category" : category.text
};
//Firebase unique child I'm trying to update
Firebase *post1Ref = [ref childByAppendingPath:myString];
[post1Ref setValue: feedItems];
这是错误:
***由于未捕获的异常'InvalidPathValidation'终止应用程序,原因:'(childByAppendingPath :)必须是非空字符串且不包含'。' '#''$''['或']''
我也尝试过使用updateChildValues,这会返回相同的错误。
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"refString"];
A0SimpleKeychain *keychain = [[Application sharedInstance] store];
A0UserProfile *profile = [NSKeyedUnarchiver unarchiveObjectWithData:[keychain dataForKey:@"profile"]];
// Create a reference to a Firebase location
NSString *theUrl = [NSString stringWithFormat:@"https://firebaseurlgoeshere/%@",profile.nickname];
// Create a reference to a Firebase location
Firebase *ref = [[Firebase alloc] initWithUrl:theUrl];
Firebase *ref2 = [ref childByAppendingPath: myString];
// Write data to Firebase
NSDictionary *feedItems = @{
@"description" : description.text,
@"url": url.text,
@"category" : category.text
};
[ref2 updateChildValues:feedItems];
答案 0 :(得分:1)
听起来childByAutoId就是你要找的东西。
试试这个:
NSDictionary *feedItems = @{
@"description" : description.text,
@"url": url.text,
@"category" : category.text
};
Firebase *post1Ref = [ref childByAutoId];
[post1Ref setValue: feedItems];
来自Firebase的更多内容:https://www.firebase.com/docs/ios/guide/saving-data.html#section-lists