'silent push notifications in react native app

We are working on a react native app, in which we have some features where we can do some actions using silent push notifications. we are using react-native-firebase for that.

For sending push notifications we are using firebase cloud functions, here is the payload structure.

 let payload = {
    token: pushToken,
    priority: normal,
    data : { 
        RequestUserID : event.params.requestId,
    }

We are not getting callbacks for app when its running in foreground or background ?

Any solution to get silent push notifications so that we can perform some tasks, when app is in foreground, background or killed ?



Solution 1:[1]

I don't think it's possible to not give an alert (unless the user disabled them) when the app is backgrounded or killed and receives a push notification. You could send data and run a task while the app is backgrounded if you use a websocket. That would not send an alert. If the app is closed, you won't be able to make it do any task.

Solution 2:[2]

You need to send you data in a notification payload instead of in a data payload. As seen in https://rnfirebase.io/messaging/usage

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Richard Lucas
Solution 2 Pablo Arellano