[英]FIRInvalidArgumentException, reason: Document path cannot be empty
我正在尝试访问我从 Firebase 快照创建的字典中的一些值,我使用这些值来访问我的 firestore 中的一些文档,但是这些值返回为空,因此我使用这些值的路径是空的,我可以t 访问 Firestore。
我不确定这些值是否嵌套在字典中,我尝试搜索访问嵌套字典,但出现其他错误。
这是 output
snapshot Optional({
16640500463403668 = {
ReciverID = "manarx224@gmail.com";
RewardKey = "Reward_25";
isScanned = 1;
};
})
Scanned successfully
16640500463403668
Dictionary is:
Optional({ 16640500463403668 = { ReciverID = "manarx224@gmail.com"; RewardKey = "Reward_25"; isScanned = 1; }; })
resciver id is
RewardKey id is
2022-09-25 02:31:20.924590+0300 KhutaaScannser[30891:1892245] *** Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Document path cannot be empty.'
这是我的代码:
let ref = ref.child("AllQRCodes")
ref.getData { [self] (error, snapshot) in
print("snapshot \(snapshot.value as Any)")
if let value = snapshot.value as? [String: Any] {
for key in value.keys {
if key == QRnumber {
self.ref.child("AllQRCodes").child(QRnumber).child("isScanned").setValue(true)
print("Scanned successfully")
self.messageLabel.text = "Succefully Scanned"
print(key)
let dictionary = snapshot.value as? NSDictionary
print("Dictionary is: " )
print(dictionary)
var ReciverID = dictionary?["ReciverID"] as? String ?? ""
var RewardKey = dictionary?["RewardKey"] as? String ?? ""
print("resciver id is" + ReciverID)
print("RewardKey is "+RewardKey)
db.collection("users").document(ReciverID).collection("UserRewards").document(RewardKey).setData( ["isScanned": true], merge: true)
print("Scanned successfully")
self.messageLabel.text = "Succefully Scanned"
self.ref.child("AllQRCodes").child(QRnumber).removeValue()
break
您没有从正确的子快照中读取。
var ReciverID = dictionary?["QRnumber"]["ReciverID"] as? String ?? ""
您可能需要在其中进行一些额外的 null 处理,因此如果您收到关于此的错误,请搜索错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.