capacitor-community / fcm

Enable Firebase Cloud Messaging for Capacitor apps
https://capacitor.ionicframework.com/docs/
MIT License
238 stars 83 forks source link

Requested entity was not found on iOS device #135

Open AlvinStefanus opened 1 year ago

AlvinStefanus commented 1 year ago

When I tried to send a push notification from my node.js server, the iOS devices got this error:

Requested entity was not found

The code to send the notification is this:

var admin = require("firebase-admin");

// Get it from firebase console -> service accounts
var serviceAccount = require("../fcmKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
});

export const sendFCM = (dest: string[], title: string, content: string) => {
  const msg = {
    data: { title, content },
    notification: {
      title,
      body: content,
    },
    tokens: dest,
  };

  admin
    .messaging()
    .sendMulticast(msg)
    .then((response: any) => {
      // Response is a message ID string.
      console.log("Successfully sent message:", response);
    })
    .catch((error: any) => {
      console.log("Error sending message:", error);
    });
};

I read that the token should be refreshed, but this library does not have a way to refresh the token.

Please advice.