James Lee
James Lee

Reputation: 926

How to setup badge count firebase push notification in ios?

I have successfully setup my backend to send notification using "firebase-admin". However, I am having trouble setting up the badge count for my ios. I am currently using react native and node.js typescript for backend.

My backend admin when sending looks like this:

const payload = {
            notification: {
                title: "title",
                body: `body`,
              //badge: 1 this throws an error
            },
            token: receiverFcmToken
        };

        try{
            await admin.messaging().send(payload).then((response) => {
                console.log("success);
            });
        } catch(err){
            console.log(err);
        }

Any help would be appreciated. Thanks

Upvotes: 0

Views: 3096

Answers (2)

Usman
Usman

Reputation: 467

const message = {
    notification: {
        title: category.title,
        body: category.message,
    },
    apns: {
        payload: {
            aps: {
                badge: 1,
                sound: 'default'
            },
        },
    },
    token: fcmToken
};

This payload worked for me. Check out the documentation here

Upvotes: 1

Mikhail Zhukouski
Mikhail Zhukouski

Reputation: 21

Your payload should look like this:

const payload = {
    notification: {
        title: "title",
        body: `body`,
    },
    apns: {
      payload: {
        aps: {
          badge: 1,
        },
      },
    },
    token: receiverFcmToken
};

Upvotes: 2

Related Questions