【问题标题】:how to add channel id to push Notification payload如何添加频道 ID 以推送通知有效负载
【发布时间】:2021-08-15 17:53:41
【问题描述】:

我正在使用带有本地通知的推送通知.. 我必须在我的有效负载中设置频道 ID.. 这是我的有效载荷

我不确定这是否适用于安卓和 ios。请帮助我正确的有效载荷。

谢谢

exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
    if (!snapshot.exists) {
        console.log('No Device');
    }
    const chatDatas = snapshot.data();
    const messageTo = chatDatas['idTo'];
    const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
    const user1name = deviceTokenuUser1.data()['name'];
    const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];

    let payload = {
        notification: {
            title: `${user1name}`,
            body: `${chatDatas['content']}`,
        },
        data: {
            key: 'chat',
            id: `${messageTo}`,
            click_action: "FLUTTER_NOTIFICATION_CLICK"
        },
        android: {
            priority: "high",
        },
        apns: {
            payload: {
                aps: {
                    contentAvailable: true,
                },
            },
            headers: {
                "apns-push-type": "background",
                "apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
                "apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
            },
        },

        token: deviceTokenuUser1.data()['tokens'],
    };
    try {
        await admin.messaging().send(payload);

        console.log("Firebase chat Messaging Successfully");
    } catch (err) {
        console.log("error from chat messaging " + err);
    }

【问题讨论】:

    标签: flutter dart push-notification


    【解决方案1】:

    您可以像这样添加频道 ID:

    let payload = {
    // ...
        android: {
            priority: "high",
            notification: {
                channelId: "yourchannelid"
            }
        }
    
    // ...
    }
    

    【讨论】:

    • iOS怎么样,请添加ios的点击动作
    • 我认为 iOS 中没有频道 ID,click_action 应该可以使用您的原始代码。
    • 这样payload将同时适用于android和iOS
    • 你必须尝试
    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 2017-07-23
    • 2017-05-31
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2016-12-08
    • 2021-04-26
    相关资源
    最近更新 更多