Skip to content

Firebase Cloud Messaging ​

MARS Engine has a very straightforward way to send Push notifications to Android/iOS devices.

You would need an application registered on Firebase beforehand. If you are not familiar with it, you can look up the process here:
Firebase Cloud Messaging Documentation

Setup ​

Once you obtain the unique device key from your app, you can send it to your MARS backend and use it to direct messages.

To send a FCM Push Notification, simply invoke the FCM() module in MARS and pass your App Key (Server Key from Firebase dashboard).

Example ​

js
const fcmMsg = FCM("FCM Key for your App");
fcmMsg.to("DEVICE_KEY:AsdAf9g1bGtxmujyJVAV00jNoPxFuwFdcXux5rZrvmenthqdfJGnN38GD-8cfx52iBG_L5HahmxCXjpb0gLhkQ2O1YT8JXQ23c8sZh46fC3B1RZKOEECSpbJIJapGzl");

fcmMsg.title("Hey, something new happened!");
fcmMsg.body("A cat has just had fifteen kittens! Click this notification for a very cute video.");

fcmMsg.send();

✅ That’s it! A push notification will be sent to the device.

⚙️ Methods ​

MethodParametersDescription
to()Device ID or array of IDsSpecify recipients (up to 1000 per message, per Google’s limits)
title()StringHeading text of the notification
sound()"default" or custom soundPlays a sound when the notification is received
body()StringSubtext or message body
color()Hex string (e.g. #fefefe)Sets background icon color
data()Map of key-value pairsHidden payload used by your app for internal behavior
send()–Sends the message to recipients

Notes ​

  • Use .send() last to trigger delivery.
  • Multiple recipients can be defined via array in .to().
  • Any unconfigured optional fields will be omitted from the payload.