Не удается получить доступ к данным из push-уведомления FCM внутри функции обратного вызова для IOS - PullRequest
0 голосов
/ 12 июня 2019

Я использую firebase FCM для отправки уведомлений пользователям в моем приложении. Я могу нормально отправлять уведомления, но при попытке доступа к данным для уведомления внутри функции обратного вызова ничего не происходит ...

Вот мой код:

//Firebase cloud function RTDB Trigger:

exports.cannectionPostNotification = functions.database.ref('/feed/{userId}/{postId}')
.onCreate((snapshot, context) => {
  const userId = context.params.userId;
  const post = snapshot.val();

  const ref = admin.database().ref(`users/${userId}/notificationTokens`);
  return ref.once("value", function(snap){
      const payload = {
            notification: {
                title: `New Post from ${post.username}`,
                body: post.capText,
            },
            data: {
              //need to access this to navigate to 
              //this screen when the notification is open...
              screen: 'imageScreen'
            },
      };

        admin.messaging().sendToDevice(snap.val(), payload)
  }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
  });
});



//App.js callback..

this.notificationOpenedListener = fire.notifications().onNotificationOpened((notificationOpen) => {
    const { title, body } = notificationOpen.notification;
    const { screen } = notificationOpen.data;
    this.showAlert(title, body);
    //alert won't show when app opens from notifiation...
    alert('NOTIFICATION OPENED' + screen);
});

Моя цель состоит в том, чтобы перейти к соответствующему экрану на основе данных из полезной нагрузки, но я не могу получить ничего от обратного вызова.

Я ценю все советы, которые я могу получить по этому вопросу,

Спасибо!

...