我有这个 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 时,使用 FEventTypeChildAddedobserverType 的第二个回调永远不会被触发吗?如果我不使用 FEventTypeValue 读取所有内容,它会起作用。但在这种情况下,当用户进入聊天室时,我的 UITableView 重新加载将被调用以处理每个待处理的消息。
最佳答案
抱歉,大家。问题出在我的代码上。 firebase 引用 (msgListRef) 在我没有注意到的另一个函数中重新初始化。
关于ios - Firebase 回调不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20995413/