Skip to content

Latest commit

 

History

History
191 lines (149 loc) · 3.53 KB

TestingPushNotifications.md

File metadata and controls

191 lines (149 loc) · 3.53 KB

Testing Push Notifications

Perform POST to https://fcm.googleapis.com/fcm/send

Using headers:

Content-Type: application/json

Authorization: key={your-fcm-server-key}

Sending to specific topic:

Android:

{
  "to": "/topics/test",
  "data": {
    "message": "hello world"
   }
}

iOS:

{
  "to" : "/topics/test",
  "priority" : "high",
  "notification" : {
    "body" : "Hello world",
    "title" : "FCM Message",
  }
}

Sending push to specific devices:

Single device

Android:

{
  "to": "{device-token}",
  "data": {
    "message": "hello world"
   }
}

iOS:

{
  "to" : "{device-token}",
  "priority" : "high",
  "notification" : {
    "body" : "Hello world",
    "title" : "FCM Message",
  }
}

Multiple devices:

Android:

{
    "data": {
         "message": "hello world"
     },
    "registration_ids": ["{device-token}","{device2-token}"]
}

iOS:

{
    "priority" : "high",
    "notification" : {
      "body" : "Hello world",
      "title" : "FCM Message"
    },
    "registration_ids": ["{device-token}","{device2-token}"]
}

Sending push to topic based on conditions:

Android:

{
    "data": {
        "message": "hello world"
     },
     "priority": "high",
     "condition": "'test' in topics"
}
{
  "condition": "'dogs' in topics || 'cats' in topics",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!"
   }
}

iOS:

{
    "priority" : "high",
    "notification" : {
      "body" : "Hello world",
      "title" : "FCM Message"
    },
    "condition": "'test' in topics"
}
{
  "priority" : "high",
  "notification" : {
    "body" : "Hello world",
    "title" : "FCM Message"
  },
  "condition": "'dogs' in topics || 'cats' in topics"
}

More information here: https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

Using Postman

Import this collection: Firebase Postman Collection

Using FirebaseNet to send push notifications:

Sending push notification to Android:

 Task.Run(async() => {
 
            FCMClient client = new FCMClient("YOUR_APP_SERVER_KEY"); //as derived from https://console.firebase.google.com/project/
            
            
            var message = new Message()
            {
                To = "DEVICE_ID_OR_ANY_PARTICULAR_TOPIC", //topic example /topics/all
                
                Data = new Dictionary<string, string>
                {
                      Body = "Hello World",
                    Title = "MyApp",
                }
            };
           
            var result = await client.SendMessageAsync(message);
            return result;
 });

Sending push notification to iOS:

 Task.Run(async() => {
 
            FCMClient client = new FCMClient("YOUR_APP_SERVER_KEY"); //as derived from https://console.firebase.google.com/project/
            
            
            var message = new Message()
            {
                To = "DEVICE_ID_OR_ANY_PARTICULAR_TOPIC", //topic example /topics/all
                Notification = new iOSNotification()
                {
                    Body = "Hello World",
                    Title = "MyApp",
                }
            };
           
            var result = await client.SendMessageAsync(message);
            return result;
 });

More information here: https://github.com/tiagomtotti/firebaseNet

<= Back to Table of Contents