参考编号是偶数,但firebase始终显示此错误:
***由于未捕获的异常'FIRInvalidArgumentException'而终止应用程序,原因:'无效的文档引用。文档引用必须具有偶数个段,但是users / UnaY1j5YFkesLTYB1iCuRP1VELJ2 / form_fillers的长度为3'
因此,每个用户可以在我的应用程序中提交大约10个表单。我使用以下代码检查该限制:
// MARK: Check for form limit
private func checkForForms(completion: @escaping (_ isLimitReached: Bool) -> Void) {
guard let fn = self.first_name.text else {
self.show_error(title:"Error", message: "First name cannot be empty")
return
}
guard let aob = self.ahv_or_birthday.text else {
self.show_error(title:"Error", message: "You must enter your birthdate")
return
}
guard let ln = self.last_name.text else {
self.show_error(title:"Error", message: "Last name cannot be empty")
return
}
DispatchQueue.global(qos: .background).async {
let document_path:String = "\(fn)\(aob)\(ln)"
let aUser = "UnaY1j5YFkesLTYB1iCuRP1VELJ2"
let docRef = self.db.collection("users").document(aUser).collection("form_fillers").document(document_path).collection("forms")
docRef.getDocuments(completion: { (document, error) in
guard let document_s = document else {
print("No Such Document")
return
}
if document_s.documents.count >= 10 {
// Show error
completion(true)
} else {
// Show success
completion(false)
}
})
}
}
应用程序崩溃。
注意: (1)当第一个人开设一个新帐户时,集合“ form_fillers”不存在,这有问题吗?
(2)文本字段不为空,每个字段的值为“ test”
(3)根文档。用户>用户ID有效。