[英]How to fetch specific data from Firestore and update it in Objective-C
I have to fetch my user from Firestore and then I want to update my image which is string.我必须从 Firestore 获取我的用户,然后我想更新我的字符串图像。 I am stuck at one place.我被困在一个地方。
Here is my code:这是我的代码:
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
FIRCollectionReference *colRef = [defaultFirestore collectionWithPath:@"users"]; // to fetch my user profile
[colRef queryWhereField:@"name" isEqualTo:currentUser.name];
[colRef getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSLog(@"%@", document.data); // my profile and after that I want to update the image
// here I want to update the user image how can I do it ??
}
}
}];
try this:试试这个:
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
FIRCollectionReference *colRef = [defaultFirestore collectionWithPath:@"users"];
FIRQuery *query = [colRef queryWhereField:@"name" isEqualTo:@"SIDDHANT Nigam"];
[query getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
FIRDocumentSnapshot *document = snapshot.documents.firstObject;
[document.reference updateData:@{
@"imageurl": @""
}];
}
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.