Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable default sound on FCM notifications for both android and iOS

After several hours searching the web for answers on how to enable the default sound on Firebase cloud messaging notifications, for both android and iOS, I finally figured it out by myself. I could not really find any answers to this problem anywhere on the web, so I thought I should post the answer here.

Hope this helps :)

like image 480
Magnus Avatar asked Jan 09 '19 22:01

Magnus


People also ask

Does FCM work on iOS?

Stay organized with collections Save and categorize content based on your preferences. For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.


1 Answers

This particular snippet is written in node.js, but except from the 3 first lines, the syntax is the same in 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);
        });
like image 109
Magnus Avatar answered Sep 22 '22 11:09

Magnus