2014-01-08 48 views
2

我有这个Firebase引用来通过传递上次读取消息的优先级来检索所有未决(未读)消息。我在聊天室里这样做。Firebase回调不会触发

NSNumber* lastPriority = [self getLastPriority]; 
__block FirebaseHandle handle = [[msgListRef queryStartingAtPriority:lastPriority] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { 

    // here I will get all the pending messages and add them to my local message list and reload the UITableView 
    [self addMessageToList: snapshot] 
    [msgListRef removeObserverWithHandle:handle]; 
    // Then I call the below function to keep listening for new messages when the chat is in progress 
    [self addMessageListener]; 

}]; 



- (void) addMessageListener{ 
     msgListRef = [[Firebase alloc] initWithUrl:messageListUrl]; 
     NSNumber* lastPriority = [self getLastPriority]; 
     [[msgListRef queryStartingAtPriority:lastPriority] observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) { 

      [self addMessageObject:snapshot.value]; 
      // Here I will reload the table view. This one is supposed to fire for each  
      //message since I used FEventTypeChildAdded. 
      //*** BUT THIS CALLBACK IS NEVER FIRED *** 

     }]; 
} 

任何想法,为什么与FEventTypeChildAdded observerType第二回调时,我之前已经叫FEventTypeValue永远不会被解雇?如果我没有使用FEventTypeValue读取全部内容,它将起作用。但在这种情况下,当用户进入聊天室时,我的UITableView重新加载将会针对每个待处理消息进行调用。

+0

你不应该使用lastPriority,而不是lastMessage.priority?另外,优先级的价值是什么?有多少条消息具有该优先级? – Kato

+0

这是一个错误的问题。我会编辑它。优先级是一个运行号码,每次有新消息进来时我都会增加。它也存储在火力点地点。 – travoux

+0

我也仔细检查你传递给子事件处理程序的优先级与值事件处理程序是否相同。 addMessageToList以某种方式修改最后的优先级? – Anant

回答

2

对不起,guys.The问题是与我的代码。 firebase引用(msgListRef)在我没有注意到的另一个函数中被重新初始化。