【问题标题】:Flutter / Firebase delayed push notificationFlutter / Firebase 延迟推送通知
【发布时间】:2021-06-13 18:43:03
【问题描述】:

大家好,我是 Flutter 开发者。

我使用 Flutter 和 Firebase 制作了聊天应用程序,但遇到了一些通知问题。

以下代码是我发送通知的方式,当在 Firebase 数据库中创建消息时,我通过 firebase 函数推送通知。

问题是,它发送通知成功,但有时会延迟几个小时或几天!!

如果哪个没有发送通知,我明白,我的代码有任何错误,

但有时它会延迟......大部分工作正常。

我怎么能理解这种情况?有没有办法管理通知速度?

感谢您的阅读,我会等待您的帮助。

exports.onCreateMessage = functions.firestore//Notification
    .document('ChatRoom/{chatRoomID}/Messages/{message}')
    .onCreate(async (snap, context) => {
        const chatRoomID = context.params.chatRoomID;
        const message = snap.data();
        const chatRoomRef = await admin.firestore().collection('ChatRoom')
            .doc(chatRoomID).get();

        //setDate to Chatroom
        chatRoomRef.ref.update({
            latestMessageID: message.messageType === CHAT_MESSAGE_TYPE_EMOJI ? '[STICKER]' : message.message,
            latestMessageTime: new Date()
        });
        const senderUserRef = await admin.firestore().collection('User').doc(message.senderID).get();
        //getUserList add  then number;
        const joinedUserList = Object.entries(chatRoomRef.data().joinedUserList);//convert obejct to map.
        joinedUserList.forEach(async (value, key, map) => {
            if (value[0] !== message.senderID) {
                const joinedChatRoomRef = await admin.firestore()
                    .collection('UserJoinedChatRooms').doc(value[0]).collection('JoinedChatRoomList')
                    .doc(chatRoomID).get();
                await admin.firestore()
                    .collection('UserJoinedChatRooms').doc(value[0]).collection('JoinedChatRoomList')
                    .doc(chatRoomID).update({
                        unReadMessageCount: joinedChatRoomRef.data().unReadMessageCount + 1,
                        latestMessageTime: new Date(),
                        isInTheChatRoom: true,
                    });
                return admin.messaging().sendToTopic(`${value[0]}`, {
                    notification: {
                        title: senderUserRef.data().name,
                        body: message.messageType === CHAT_MESSAGE_TYPE_EMOJI ? '[STICKER]' : message.message,
                        clickAction: 'FLUTTER_NOTIFICATION_CLICK',
                        sound: 'default'
                    }
                    , data: {
                        notificationType: message.messageType.toString()
                    }
                });
            }
            else {
                await admin.firestore()
                    .collection('UserJoinedChatRooms').doc(value[0]).collection('JoinedChatRoomList')
                    .doc(chatRoomID).update({
                        latestMessageTime: new Date(),
                    });
            }
        });
    });

【问题讨论】:

  • 通知延迟几天是不可能的......你到底是什么意思它延迟了?你在哪里检查这个?

标签: firebase flutter push-notification google-cloud-functions firebase-cloud-messaging


【解决方案1】:

firebase 通知没有速度,只要你将数据提交到 firebase 并且用户在线它就会显示出来。

【讨论】:

  • 糟糕的答案。首先,不,用户不必在线即可显示通知。如果应用程序处于后台或终止状态,您可以配置 firebase 以接收通知。其次,为什么会有人等待不可接受的几分钟或几小时才能收到通知?特别是在聊天应用程序中。这太荒谬了。
  • 你在说什么我在网上说,你在说应用程序是否在后台。两者有很大区别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 2019-05-07
  • 1970-01-01
  • 1970-01-01
  • 2020-08-05
  • 1970-01-01
相关资源
最近更新 更多