简体   繁体   中英

What is the best approach to passing data from a notification to the application that it opens, using “react-native-firebase v6”?

I want to implement opening a specific screen when interacting with a Push Notification sent from Firebase. My understanding is that I needed to use was getInitialNotification() function that was available in react-native-firebase v5 and lower, but is not available yet in react-native-firebase v6 , since the Notifications package is not yet ready. Among other things, so far I have tried setting the background message handler that is available in the Cloud Messaging package, but it doesn't seem to work for something that is not a data-only message:

Firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => { await storeJSONData('notification', JSON.stringify(remoteMessage)); });

Should I downgrade to react-native-firebase v5 in order to use their getInitialNotification() from the Notifications package, or do I have other better alternatives, like even using android native code?

I eventually solved this issue by using the react-native-push-notification package on top of the firebase cloud messaging and implementing the onNotification function from that one.

PushNotification.configure({
      onNotification: function(notification)
      {
        // process the notification
        console.log('NOTIFICATION:', notification);
        //iOS only
        notification.finish(PushNotificationIOS.FetchResult.NoData);
      },
      permissions: {
        alert: true,
        badge: true,
        sound: true
      },
      popInitialNotification: true,
      requestPermissions: true,
});

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