2016-12-23 104 views
0

我在查询中将所有断点设置为Firebase,并且发生的所有事情都是以下行的断点(这是第一行),然后是其他行。Firebase查询未被触发

_CHAT_REF.observeEventType(.Value, withBlock: { snapshot in 

任何想法为什么会发生这种情况?即使没有数据,查询块内的断点仍然会被击中,但它们不是。我所做的:我已经卸载并重新安装了Firebase至少10次,使用CocoaPods而不是CocoaPods,按照T指示。我没有收到任何类型的编译错误,并且正在运行FIRApp.configure ()在我的应用程序委托。

完整的代码(每行断点,没有所谓唯一_CHAT_REF.observe线):

private var _CHAT_REF = FIRDatabase.database().reference().child("chats") 

_CHAT_REF.observeEventType(.Value, withBlock: { snapshot in 

    self.individualMessages = [] 

    if snapshot.hasChildren() { 
     // Found chats 
     for snap in snapshot.children { 
      let theChat = Chat(snapshot: snap as! FIRDataSnapshot) 

      // The current user belongs to this chat, so add it to individual messages. 
      if theChat.sender_id == GlobalEnv.currentUser.id || theChat.receiver_id == GlobalEnv.currentUser.id { 
       self.individualMessages.append(theChat) 
      } 
     } 
    } else { 
     // No Children 
     print("No children found.") 
    } 
    self.tvContacts.reloadData() 
}) 

DB结构:

DB Structure on Firebase

+1

什么_CHAT_REF看起来不一样? – Barrett

+0

private var _CHAT_REF = FIRDatabase.database()。reference()。child(“chats”) – Belvedare

+0

你的数据库结构是什么样的? – Barrett

回答

1

我遇到了类似的问题。事实证明,我无法从组织的代理服务器后面读取/写入数据库。我使用开放式WiFi构建到设备上,并且工作正常。

+0

我似乎可以从其他应用程序读取/写入,只需使用Firebase即可。这只是一个,我添加了Firebase的旧Swift项目,我遇到了问题。我也尝试过另一个设备和wifi,现在没有运气。 – Belvedare

+0

大鼠;对不起,没有工作。 –

1

试试这个,让我知道它是否有所作为。它非常简化,但变量赋值的处理方式不同。

假设你是在一个视图控制器类...

class ViewController: UIViewController { 
    var ref: FIRDatabaseReference! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     ref = FIRDatabase.database().reference() 
    } 

    func clickAction() { //just tied to an action in the UI 
     let chatsRef = ref.child("chats") 
     chatsRef.observeEventType(.Value, withBlock: { snapshot in 
     print("Hello, World") 
     }) 
    } 
}