更新时间:2023-12-05 22:49:28
将代码更改为以下内容:
Change your code to the following:
// Add a new document with a generated ID
var ref: DocumentReference? = nil
ref = db.collection("users").addDocument(data: [
"firstname": firstname,
"lastname": lastname,
"uid": result!.user.uid
]) { err in
if let err = err {
print("Error adding document: \(err)")
} else {
print("Document added with ID: \(ref!.documentID)")
}
}
使用此打印语句 print(添加文档时出错:\(err)")
您可以确切地知道错误是什么.
Using this print statement print("Error adding document: \(err)")
you can know exactly what the error is.
还将您的安全规则更改为以下内容:
Also change your security rules to the following:
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}