【问题标题】:Enable default sound on FCM notifications for both android and iOS为 Android 和 iOS 启用 FCM 通知的默认声音
【发布时间】:2023-03-17 06:39:03
【问题描述】:

在网上搜索了几个小时以寻找有关如何在 Android 和 iOS 上启用 Firebase 云消息通知的默认声音的答案后,我终于自己弄明白了。我在网上的任何地方都找不到这个问题的任何答案,所以我想我应该在这里发布答案。

希望这会有所帮助:)

【问题讨论】:

    标签: node.js firebase firebase-cloud-messaging firebase-admin


    【解决方案1】:

    这个特殊的 sn-p 是用 node.js 编写的,但除了前 3 行之外,在 Typescript 中的语法是相同的。

        const functions = require('firebase-functions');
        const admin = require('firebase-admin');
        admin.initializeApp(functions.config().firebase);
    
        const payload = {
            notification: {
                title: "X",
                body: "XXX",
            },
            android: {
                notification: {
                    sound: 'default'
                },
            },
            apns: {
                payload: {
                    aps: {
                        sound: 'default'
                    },
                },
            },
            topic: 'X'
        };
        return admin.messaging().send(payload).then(response => {
                console.log("Successfully sent message:", response);
            })
            .catch(function (error) {
                console.error("Error sending message:", error);
            });
    

    【讨论】:

    • 对.. 谢谢,这里有一个文档:firebase.google.com/docs/reference/fcm/rest/v1/… 但你拥有的文档很简单。
    • 我收到 - 消息负载包含无效的 \"android\" 属性。有效的属性是 \"data\" 和 \"notification\.... :\
    • 确保您使用的是messaging().send 而不是messaging().sendToDevice
    猜你喜欢
    • 2018-11-25
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    相关资源
    最近更新 更多