Firebase / iOS 更新数据
Firebase / iOS updating data
如何更新 Firebase 中生成的 child 记录?我收到以下关于特殊字符的错误,有没有办法生成没有特殊字符的 child 自动 ID?
这是 child 自动 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];
这是错误:
*** Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(childByAppendingPath:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
我也尝试过使用 updateChildValues,这 returns 同样的错误。
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];
听起来 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
如何更新 Firebase 中生成的 child 记录?我收到以下关于特殊字符的错误,有没有办法生成没有特殊字符的 child 自动 ID?
这是 child 自动 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];
这是错误:
*** Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(childByAppendingPath:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
我也尝试过使用 updateChildValues,这 returns 同样的错误。
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];
听起来 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