我有这个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 ***
}];
}
在我之前调用了FEventTypeValue时,有没有想过为什么第二次回调FEventTypeChildAdded observerType永远不会被触发?如果我没有用FEventTypeValue读取所有内容,它就可以工作。但是在这种情况下,当用户进入聊天室时,我的UITableView重新加载将被调用每个待处理的消息。
答案 0 :(得分:2)
对不起伙计们。问题出在我的代码上。 firebase引用(msgListRef)在另一个我没注意到的函数重新启动。