firebase子快照检索不起作用

时间:2017-12-02 20:03:51

标签: swift firebase firebase-realtime-database avcapturesession

我正在为条形码扫描器编写代码,扫描条形码并在firebase数据库中搜索条形码。我能够使条形码工作,我可以检索扫描的条形码数字,但我通过firebase运行条形码无法正常工作。这是我的代码。

   if metadataObj.stringValue != nil {
            var productbarcode = metadataObj.stringValue
            messageLabel.text = productbarcode

            let catalogue = ref.child("UPC").child(productbarcode!)
            catalogue.observeSingleEvent(of: .value, with: { (snapshot) in
                let value = snapshot.value as? NSDictionary
                print(value)

            }){ (error) in
                print(error.localizedDescription)
            }

            print("Barcode detected")

        }

我希望它能够打印与扫描条形码匹配的firebase节点快照,如果找不到它则会打印错误。 遗憾的是,当有一个快照时,它不会打印快照,或者当它在firebase DB中找不到时,它不会打印错误消息。我做错了什么,我该如何解决这个问题?

0 个答案:

没有答案