5

I am sending a push token to a specific device via the FCM API on testing with Postman, but I intend to send them from the server.

{
    "to" : "my_device_token",
    "notification" : {
        "notificationTitle" :"test from server",
        "notificationBody" :"test lorem ipsum"
    }
}

I am receiving the response

{
    "multicast_id": 4996861050764876123,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": 
    [
        {
            "message_id": "0:1519567530487886%f95ee7d4f95ee123"
        }
    ]
}

Which shows no error, however I don't get any notifications on my phone. I tried the same device token using on firebase website "Notifications => New Message => Single Device", and it works.

I see threads about not receiving the notifications when the app is not running, however I don't get any even if the app is running.

Edit: My application is built using Xamarin.Android, if relevant.

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
bsoolius
  • 75
  • 1
  • 9

3 Answers3

5

The notification property keys are title and body:

{
    "to" : "my_device_token",
    "notification" : {
        "title" :"test from server",
        "body" :"test lorem ipsum"
    }
}

See Table 2b in the documentation.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
0

I am sending push in a single devices using via FCM api. The JSON is given below.

In the case of Android

         {
            "to" : "device Tokens", // Your android device token 
            "data" : 
            {
                "body" : "test",
                "title" : "test",
                "pushtype" : "events",
            };

In the case of IOS json

          {
            "to" : "device Tokens", // iphone tokens
            "data" :
            {
                "body" : "test",
                "title" : "test",
                "pushtype" :"events",
            },
            "notification" :  {
                    "body" : "test",
                    "content_available" : true,
                     "priority"  "high",
                    "title" = "C#"
           }
    } ;
0
put in index.js

PushNotification.configure({
    onNotification: function (notification) {
        console.log("NOTIFICATION:", notification);
      },
      requestPermissions: Platform.OS === 'ios'
})

in your screen
createChannels =()=>{
       PushNotification.createChannel(
           {
               channelId:"test-channel",
               channelName:"Test-channel"
           }
       )
}

handleNotification=()=>{
    PushNotification.localNotification({
        channelId:"test-channel",
        title:"Kinza ",
        message: "hi gow adww biy",     
    });
    PushNotification.localNotificationSchedule({
        channelId: "test-channel",
        title:"Alram",
        message:"Hi how are you",
        date: new Date(Date.now() + 20*1000),
        allowWhileIdle:'true',
    });
}
  • 1
    Appreciate the answer, @Nauman. A brief description on how the code works shall add more value to your answer. – Sukhi Dec 02 '21 at 07:13
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 02 '21 at 07:13