ios - Firebase 回调不会触发

标签 ios objective-c 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 ***

        }];
}

知道为什么当我之前已经调用过 FEventTypeValue 时,使用 FEventTypeChildAddedobserverType 的第二个回调永远不会被触发吗?如果我不使用 FEventTypeValue 读取所有内容,它会起作用。但在这种情况下,当用户进入聊天室时,我的 UITableView 重新加载将被调用以处理每个待处理的消息。

最佳答案

抱歉,大家。问题出在我的代码上。 firebase 引用 (msgListRef) 在我没有注意到的另一个函数中重新初始化。

关于ios - Firebase 回调不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20995413/

相关文章:

ios - didReceiveLocalNotification 在 iOS6 中未激活

php - iOS 推送通知 PHP 错误

ios - 启动画面以倒置方式出现?

objective-c - 检查字典数组是否包含带键的字典的快速方法?

javascript - 是否可以使用 Firebase Javascript SDK 访问用户的 Twitter 访问 token 和 secret ?

iphone - 图片没有上传到网络服务

ios - UICollectionViewDelegateFlowLayout UICollectionViewFlowLayout 之间的区别

objective-c - 用户默认值从 Obj C 迁移到 Swift

swift - “不支持嵌套数组”FireStore Swift iOS

android - 连接 Firebase 和 Carto