Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can specify the priority on FCM message?

I'm using react-native-firebase to manage notifications on React-native app. I try to handle FCM message on the background when application is off without display the notification.

I’m using react-native-firebase to manage notifications on React-native app. When my app is off, I try to catch FCM messages and wake up my app without displaying any notification, just as described here https://rnfirebase.io/docs/v4.2.x/messaging/introduction#Data-only-messages 1.

In React Native Firebase doc, they say :

You will need to specify the FCM message priority as high for this functionality to work. If this isn’t set, the app is not given permission to launch the background message handler.

Where I must specify this priority ? I don’t understand how this works.

Edit 1 : I tried to set priority : "high"on FCM message but it's still not working. I have the same problem related to this issue : https://github.com/invertase/react-native-firebase/issues/500

like image 206
Quentin Burg Avatar asked Jun 11 '18 16:06

Quentin Burg


People also ask

How do I set priority in FCM?

You have two options for assigning delivery priority to downstream messages on Android: normal and high priority. Delivery of normal and high priority messages works like this: Normal priority. This is the default priority for data messages.

How do I send a notification to a specific user?

Click Log in and register and verify a dialog shows that you have logged in. This code also enables the Send Push button. Then in the Recipient Username Tag field, enter the user name registered. Enter a notification message and click Send Push.


2 Answers

The priority is considered as a platform specific config. You can set different priorities for different platforms.

For instance look at the example below: (Message priority in Fcm docs)

{
  "message":{
    "topic":"subscriber-updates",
    "notification":{
      "body" : "This week's edition is now available.",
      "title" : "NewsMagazine.com",
    },
    "data" : {
      "volume" : "3.21.15",
      "contents" : "http://www.news-magazine.com/world-week/21659772"
    },
    "android":{
      "priority":"normal"
    },
    "apns":{
      "headers":{
        "apns-priority":"5"
      }
    },
    "webpush": {
      "headers": {
        "Urgency": "high"
      }
    }
  }
}
like image 154
Mahdi-Malv Avatar answered Oct 07 '22 02:10

Mahdi-Malv


Using "priority":10 did the trick for me.

curl -X POST --header "Authorization: key=<your_key>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d  {"data":{"body":"Test body from curl"},"registration_ids":["<reg_ids>"],"apns":{"headers":{"apns-priority":"10"}},"webpush":{"headers":{"Urgency": "high"}},"android":{"priority":"high"},"priority":10}
like image 35
Adam Kis Avatar answered Oct 07 '22 01:10

Adam Kis