Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

G.8 Understanding FCM Messages

Hadi Tavakoli edited this page Sep 26, 2018 · 3 revisions

Understanding FCM Messages

With Firebase FCM service you can send different type of data to devices. Understanding the different between these messages can be very helpful to you when deciding how to build your application.

Notification Messages

When you send a notification message, it means that all you want to do is to notify your users about a news or something and you don't wish to send any payload variables to them. When a notification message is sent, depending on the device's status, the FCM SDK will behave differently.

  • If app is in foreground mode the FcmEvents.MESSAGE event will be dispatched so you know a notification message has been received. There will be no useful payload variables with it though. It's just to notify you!
  • If app is in background mode or killed, the device will build a notification which will be shown on the device's status bar. clicking on that notification will open your app. You should not expect to receive any payload variables on the InvokeEvent.INVOKE event because this is just a notification message.

A notification message you are sending from your server might look like the following:

{
	"notification": 
	{
		"title": "Title",
		"text": "Your Text",
		"badge": "4",
	},
	"priority": "high",
	"registration_ids": 
	[
		"cKXE9N6gZ_M:APA91bH04p4ZUFdyzqqKYUySPH3fTPYUWQGkYuT-yBGcpBcv_aW",
		"cNAk9En1QfM:APA91bFWJ0YbgnsVfuJE2BxUDMmpnt6CeWQA0isZBTAxPHikxK6",
		"cAMxajJxy2Y:APA91bHkJiRUhzsowbeHtFbsEAPv-ppaSgKpzeH08f12gppv9EU",
		"dgNU5axXqfo:APA91bGgwGcVtDZKI81qMepH49oDUhphdwtqeyf-5TTSoktQ2AE",
		"dSCy3H0D99I:APA91bEmylmTU9HJzPej4R1SChVjd5FskD61nX2wT8p4bwdzVpgv"
	]
}

Data Messages

Data messages are the exact opposite of notifications in a sense that they never generate a notification alarm in your device by default. They will be received as a bunch of payload data. You may do different stuff in your app based on the received data. It totally depends on you. One of the things you can do with Data messages when they are delivered to your app is maybe to generate a custom local notification! When designing your application if you want to use Data messages, you must know how they work depending on the status of your app.

  • If app is in foreground mode, the FcmEvents.MESSAGE event will be dispatched and it will give you access to the payload data through the e.msg parameter.
  • If app is in background mode:
    • Android: Although the app is in background, the FcmEvents.MESSAGE event will be dispatched as soon as the Data message is received.
    • iOS: unlike the Android side, the Data message will wait for the app to come to foreground mode first and then the FcmEvents.MESSAGE event will be called.
  • If app is killed, when a Data message is received, nothing will happen visually but these messages will pile-up each other and they will wait for when the application runs. As soon as the application starts and the FCM ANE is initialized, these messages will be dispatched through the FcmEvents.MESSAGE event.

A Data message you are sending from your server might look like the following:

{
	"data": 
	{
		"key": "value"
	},
	"priority": "high",
	"registration_ids": 
	[
		"cKXE9N6gZ_M:APA91bH04p4ZUFdyzqqKYUySPH3fTPYUWQGkYuT-yBGcpBcv_aW",
		"cNAk9En1QfM:APA91bFWJ0YbgnsVfuJE2BxUDMmpnt6CeWQA0isZBTAxPHikxK6",
		"cAMxajJxy2Y:APA91bHkJiRUhzsowbeHtFbsEAPv-ppaSgKpzeH08f12gppv9EU",
		"dgNU5axXqfo:APA91bGgwGcVtDZKI81qMepH49oDUhphdwtqeyf-5TTSoktQ2AE",
		"dSCy3H0D99I:APA91bEmylmTU9HJzPej4R1SChVjd5FskD61nX2wT8p4bwdzVpgv"
	]
}

Mix Messages

As the name suggests, these kind of messages are a mixture of Notification and Data messages. But you should keep in mind that this name "Mix Messages", is something that we have came up with to be able to explain the differences easier. The official Firebase documentation says that there are only two types of FCM messages. But I think it's a very good idea to consider a third type as we explain below.

NOTICE 1: Firebase documentation says that mix messages are considered as notification messages which can hold payload data with them.

NOTICE 2: If you are using the official Firebase console to send FCM messages, you should know that you are ALWAYS sending Notification messages which you may add payload data to it but if you wish to send Data messages, you have to send them from your own server. I can predict that Firebase console will be updated in future to support Data messages too, but as right now, (Oct 19th, 2016), their console can be used to send notification type messages only.

Mix Messages are used when you wish to notify users' devices while sending a payload data to the app. Depending on your app status, these messages work differently.

  • If app is in foreground mode, the FcmEvents.MESSAGE event will be called and you will have access to the payload data through the e.msg parameter.
  • If app is in background mode or killed, FCM SDK will build a notification in your device's status bar. When you click on that notification, your app will come to foreground (or will launch if it was killed before) and you can receive the payload data if your app is listening to the InvokeEvent.INVOKE event.

A Mix message you are sending from your server might look like the following:

{
	"notification": 
	{
		"title": "Your Title",
		"text": "Your Text",
		"badge": "8",
		
		"click_action": "MY_INTENT"
	},
	"data": 
	{
		"obj": 
		{
			"Variable1":"value1",
			"Variable2":"value2"
		}
	},
	"priority": "high",
	"registration_ids": 
	[
		"cKXE9N6gZ_M:APA91bH04p4ZUFdyzqqKYUySPH3fTPYUWQGkYuT-yBGcpBcv_aW",
		"cNAk9En1QfM:APA91bFWJ0YbgnsVfuJE2BxUDMmpnt6CeWQA0isZBTAxPHikxK6",
		"cAMxajJxy2Y:APA91bHkJiRUhzsowbeHtFbsEAPv-ppaSgKpzeH08f12gppv9EU",
		"dgNU5axXqfo:APA91bGgwGcVtDZKI81qMepH49oDUhphdwtqeyf-5TTSoktQ2AE",
		"dSCy3H0D99I:APA91bEmylmTU9HJzPej4R1SChVjd5FskD61nX2wT8p4bwdzVpgv"
	]
}

NOTICE 3: Make sure you are adding the "click_action": "MY_INTENT" parameter in your notification branch. Missing this parameter will prevent notifications from launching your app on the Android side.

we have written a very helpful post about how you can build your own FCM console for sending out FCM messages. You can find the article here.

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally