简体   繁体   中英

React Native Firebase Push Notifications not firing production FCM/ Cloud Functions

I am trying to implement push notifications and have the same cloud functions deployed for dev and prod. For dev I am able to receive the notifications every time:

在此处输入图片说明

But for prod I get an error and it will never send:

在此处输入图片说明

Here is my notifications method:

// shows the users of the chat channel
const messageId = functions.database.ref(
  "/ChatMessages/{channelType}/{channelId}/{messageId}"
);

// HANDLE NEW NOTIFICATION
    export const notificationCreatedEvent = messageId.onCreate((snapshot: any, event: any) => {
      // channelType is for if it is a public or private chat- if it is public it will list the mountain
      const { channelId } = event.params;

      const messageData = snapshot.val();
      const message = messageData.text;

      const trimmedMessage = truncate(message, 20, true);

      // notification channel
      const notificationRef = admin
        .database()
        .ref(`/Notifications/${channelId}`);

      const notificationBody = (message.slice(0, 12) === "https://fire") ? "new image message" : trimmedMessage
      const payloadPrivateUser = {
        notification: {
          title: "Private Message",
          body: "Message: "+notificationBody
        }
      }
      const payload = {
        notification: {
          title: "Message in channel "+ channelId,
          body: "Message: " + notificationBody
        }
      }

      notificationRef
        .once("value")
        .then(async userListSnapshot => {
          const userList = await (<any>Object).values(userListSnapshot.val());
          const response = channelId.length > 50 ? await admin.messaging().sendToDevice(userList, payloadPrivateUser): await admin.messaging().sendToDevice(userList, payload);
        }).catch(err=> {
          console.log(err)
        })
    });

No idea why it would fire in one vs the other since both have the same promise error anyway?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM